svelte-kit package command for building components
See original GitHub issueNow that #511 is merged, it makes sense to have an issue for this, if only to bat around ideas. It doesn’t need to be part of the public beta, but ideally would be part of 1.0.
To recap:
Almost every app has an internal library of some sort. In a SvelteKit app, the library lives in src/lib
and is available as $lib
. Meanwhile, almost every component library has a demo/documentation site, or at the very least something Storybook-esque during development.
Therefore an app and a component library are the same thing, but with a different focus: in SvelteKit, an app is a project where the content of src/routes
is the important thing, while a component library is a project where the content of src/lib
is the important thing. Other than that, they’re basically the same, and can benefit from the same development workflow.
We already have a way of building apps — svelte-kit build
. Component libraries also need to be built for distribution. We should add a svelte-kit package
command (open to alternative name suggestions) that does the following:
- Finds components/modules that should be public. I’d suggest the same logic as in
src/routes
— any file that doesn’t have a leading_
in its filename (or that of a parent directory) is considered public - Builds them for distribution. In the case of
.svelte
files, this would mean applying preprocessors, but otherwise leaving components uncompiled. In the case of everything else, it would presumably mean running everything through the same Vite config as would normally apply to an app, except on a 1:1 transform basis since bundling is probably impossible to do in the general case given the requirement to leave.svelte
files uncompiled - Creates a
package.json
with an"exports"
field that exposes the public files (with similar name handling as routes — for example asrc/lib/Foo/index.svelte
might becomeimport Foo from 'my-lib/Foo'
) - Probably some other stuff
The output of this would be a dist folder with everything the component library needs neatly packaged up, ready for npm publish
.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:6 (2 by maintainers)
Top GitHub Comments
This exists now: https://kit.svelte.dev/docs#packaging
Could anyone please provide / point to an example Svelte Kit configuration that produces UMD/ESM/CJS components? Does this require defining your own rollup config from scratch?