sveltejs / svelte-preprocess

A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
MIT License
1.73k stars 147 forks source link

Is there a specialised syntax to support dynamically named components for Pug? #575

Closed geoidesic closed 1 year ago

geoidesic commented 1 year ago

E.g.

<script>
  let componentName = 'ComponentA';
  import ComponentA from './ComponentA.svelte';
  import ComponentB from './ComponentB.svelte';
</script>

{#if componentName === 'ComponentA'}
  <svelte:component this={ComponentA} />
{:else}
  <svelte:component this={ComponentB} />
{/if}

If not, please make this a feature request! If so, please document it :)

geoidesic commented 1 year ago

Never mind, this works:

div
   svelte:component(this="{componentObject}")