one-spa-svelte
one-spa-svelte is a helper library that helps implement one-spa registered application lifecycle functions (bootstrap, mount and unmount) for for use with svelte. Check out the one-spa-svelte github.
Quickstart
First, in the one-spa application, run npm install --save one-spa-svelte. Then, create an entry file with the following.
import oneSpaSvelte from "one-spa-svelte";
import myRootSvelteComponent from "my-root-svelte-component.js";
const svelteLifecycles = oneSpaSvelte({
component: myRootSvelteComponent,
domElementGetter: () => document.getElementById("svelte-app"),
props: { someData: "data" },
});
export const bootstrap = svelteLifecycles.bootstrap;
export const mount = svelteLifecycles.mount;
export const unmount = svelteLifecycles.unmount;
Options
All options are passed to one-spa-svelte via the opts parameter when calling oneSpaSvelte(opts). The following options are available:
component: (required) The root component that will be rendered. This component should be compiled by svelte and not an iife.domElementGetter: (optional) A function which will return a dom element. The root component will be mounted in this element. If not provided, a default dom element will be provided.
Svelte-specific options
anchor: (optional) A child of the dom element identified bydomElementGetterto render the component immediately beforehydrate: (optional) See the svelte Creating a component documentationintro: (optional) Iftrue, will play transitions on initial render, rather than waiting for subsequent state changesprops: (optional) An object of properties to supply to the component
one-spa props
All one-spa props are passed to the svelte component as props. The props provided to oneSpaSvelte({props: {...}}) are merged with the one-spa props.