Skip to content

Instantly share code, notes, and snippets.

@natxoski
Last active March 11, 2020 01:35
Show Gist options
  • Save natxoski/37f19fc03c7a966075de6946ccd7893d to your computer and use it in GitHub Desktop.
Save natxoski/37f19fc03c7a966075de6946ccd7893d to your computer and use it in GitHub Desktop.
Svelte Components Dynamic Import
<script>
export let templatePath;
let module;
if (!!templatePath && templatePath != "") {
import(templatePath)
.then(m => {
module = m.default;
return;
})
.catch(err => console.log(err));
}
</script>
{#if !!module}
<svelte:component this={module} {...$$props}/>
{:else }
Error loading your component. Check your path on templatePath prop.
{/if}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment