question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

svelte-kit package command for building components

See original GitHub issue

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 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 a src/lib/Foo/index.svelte might become import 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:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
benmccanncommented, Jul 15, 2021
4reactions
lokimckaycommented, Oct 21, 2021
  • A bundle that can be loaded directly in a browser (typically UMD output)
  • Different environments: ES Modules, CommonJS

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Packaging • Docs • SvelteKit
You can use SvelteKit to build apps as well as component libraries, ... Running the svelte-package command from @sveltejs/package will take the contents...
Read more >
How to Create Svelte Component Libraries with SvelteKit
The above command will take the contents of src/lib and generate a package directory. As you can see in the following image, it...
Read more >
Create a SvelteKit Component Library | Rodney Lab
1. Decide which components from an existing app you want to add to your component library. 2. Create a skeleton SvelteKit project. 3....
Read more >
Build your own component library with Svelte - LogRocket Blog
The above command will publish the package we have created using SvelteKit. Make sure that the package name and package version combination don' ......
Read more >
How to Create Svelte Component Libraries with SvelteKit
... SvelteKit to build component libraries as well as apps. So I'm going to tell you every single step including publishing the package...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found