Export a component from a larger SvelteKit project
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
It should be possible to export a single Component as a .js file with inlined CSS. This is super useful for building micro-frontends. With sveltes new capability to attach to a shadow-dom, single components can be exported and be used in another app by ether calling new Component(...) or by using svelte:fragment.
Currently this can only be achieved by using a separate rollup config.
Describe the proposed solution
Just another key in the config to describe which files should be exported and in which format.
Example svelte.config.js:
...
const config = {
...
external: [
{
input: 'lib/Example.svelte',
output: 'external/Example.js',
format: 'iife'
}
]
...
}
...
Alternatives considered
Use vites library mode. Currently this leads to the error "UMD and IIFE output formats are not supported for code-splitting builds."
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the svelte.config.js configuration and the current Rollup/Vite build behavior, including the library-mode code-splitting limitation. Define how component inputs, output paths, formats, and inlined CSS should be represented, then verify that a single component can be consumed as the requested JavaScript output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, rollup, vite
- Domain
- build-system, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100