Skip to content

Export a component from a larger SvelteKit project #2123

Open
@micschwarz

Description

@micschwarz

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions