PackagingEdit this page on GitHub
svelte-kit packageis currently experimental and is not subject to Semantic Versioning rules. Non-backward compatible changes may occur in any future release.
You can use SvelteKit to build component libraries as well as apps.
When you're creating an app, the contents of
src/routes is the public-facing stuff;
src/lib contains your app's internal library.
A SvelteKit component library has the exact same structure as a SvelteKit app, except that
src/lib is the public-facing bit.
src/routes might be a documentation or demo site that accompanies the library, or it might just be a sandbox you use during development.
svelte-kit package will take the contents of
src/lib and generate a
package directory (which can be configured) containing the following:
- All the files in
src/lib, unless you configure custom
- Type definitions (
typescript >= 4.0.0and
svelte2tsx >= 0.4.1for this. Type definitions are placed next to their implementation, hand-written
d.tsfiles are copied over as is. You can disable generation, but we strongly recommend against it.
package.jsoncopied from the project root with all fields but the
"dependencies"field is included, which means you should add packages that you only need for your documentation or demo site to
"type": "module"and an
"exports"field will be added if it's not defined in the original file.
"exports" field contains the package's entry points. By default, all files in
src/lib will be treated as an entry point unless they start with (or live in a directory that starts with) an underscore, but you can configure this behaviour. If you have a
src/lib/index.svelte file, it will be treated as the package root.
For example, if you had a
src/lib/Foo.svelte component and a
src/lib/index.js module that re-exported it, a consumer of your library could do either of the following:
Foo} from 'your-library';
To publish the generated package:
npm publish ./package
./package above is referring to the directory name generated, change accordingly if you configure a custom