Skip to content

svelte-kit package command for building components #518

Closed
@Rich-Harris

Description

@Rich-Harris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions