Register
To render Svelte components in Node.js without bundling, use require('svelte/register')
. After that, you can use require
to include any .svelte
file.
The
.default
is necessary because we're converting from native JavaScript modules to the CommonJS modules recognised by Node. Note that if your component imports JavaScript modules, they will fail to load in Node and you will need to use a bundler instead.
To set compile options, or to use a custom file extension, call the register
hook as a function:
Next Script ->