sveltejs / sveltejs/kit

Optionally add compiled/bundled version of library when using the package command

Open
#2,572 16 comments 34 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-nice-to-have pkg:svelte-package
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Right now sveltekit package only preprocesses TS/Svelte files to JS/"vanilla Svelte" files and exports these in their raw form. This is good when you want to use the library within another Svelte project, which is probably the 80% use case.
However, if you want to use the component library as-is, for example on another project not using Svelte, you need to add this functionality on your own currently.

Describe the proposed solution

Add an option to also provide a ESM-style bundled version of the component library. Provide that as an export for the "main" or "module" export. What I'm not sure about here is how to then differentiate between the compiled and raw version when generating the "exports" field. Should we double down on the "special svelte field" and do

"exports": {
  ".": {
     "import": "...",
     "svelte": "..."
  }
}

?

If so, which tooling packages need updating for this to work correctly?

Another idea: Provide the bundle inside a special folder called standalone, so people using the bundle would do import { SomeComponent } from 'some-library/standalone';. This would make it easier for bundlers/tooling because they wouldn't have to know about the "svelte" field. I think this is my prefered solution.

Alternatives considered

Some docs on how to achieve this

Importance

would make my life easier

Additional Information

Continuation of #518

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the sveltekit package command and how it currently emits raw JavaScript and vanilla Svelte files. Review the proposed main/module, exports, and standalone alternatives, including the tooling packages that may need updates. Done means an optional ESM bundle is produced with a documented, unambiguous import path.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.