-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
svelte-kit package command for building components #518
Comments
I like this idea! I think the trickiest part is going to be preprocessing. There's an issue in |
First, thanks for all your work on Svelte and SvelteKit, it's all really promising! It would be awesome when setting up a library would be as simple as running a single command, like setting up a new app 😎 From a library developer perspective, the following are the points that give me a hard time when setting up a new a library:
Those outputs have overlap. I can imagine in the end it is sufficient to generate three outputs to address all those needs I list above: Svelte, ES bundle, UMD bundle. |
This exists now: https://kit.svelte.dev/docs#packaging |
Awesome, thanks for all your effort! After some difficulties I managed to refactor the setup of my library to SvelteKit 😎 . The refresh speed of the dev server is really a game changer 🚀 . |
Could anyone please provide / point to an example Svelte Kit configuration that produces UMD/ESM/CJS components? |
As far as I understand you have to create a separate config for that yourself. I did that in https://github.com/josdejong/svelte-jsoneditor/ for now, but it is not ideal. Right now both svelte code and bundles are published in a single npm package. It is probably better though to publish two separate npm packages instead. |
Now 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 ofsrc/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 asvelte-kit package
command (open to alternative name suggestions) that does the following:src/routes
— any file that doesn't have a leading_
in its filename (or that of a parent directory) is considered public.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 uncompiledpackage.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'
)The output of this would be a dist folder with everything the component library needs neatly packaged up, ready for
npm publish
.The text was updated successfully, but these errors were encountered: