sveltejs / sveltejs/kit

Export a component from a larger SvelteKit project

Open
#2,123 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pkg:svelte-package
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.