Svelte template for custom elements with storybook and i18n configured. Allows nested Svelte components, nested styling and Svelte transitions.
TODO:
Clone it with degit:
npx degit redradix/svelte-custom-element-template my-new-component
cd my-new-component
yarn install # or npm
yarn start
Start making your own modifications watching changes in Storybook.
yarn build
public
folderpublic/index.html
filevendor
folder (accesible from index.html
)defer
attribute<script defer src="vendor/svelte-custom-element.0.1.0.min.js"></script>
index.html
and enjoy the web componentBuilding custom elements with Svelte is really easy but have a lot of limitations, is this template I'm trying to show the way I solve most of these limitations.
Svelte current limitations:
The code of your component lives inside /src/index.svelte
, this is the main point for either Storybook and the building process. It's important that this file has it's own style tag with content in it, otherwise we cannot inject the styles of your app inside the shadow DOM of the custom element. (read the build script)
The global styles for your Svelte component lives inside /src/styles.svelte
, this file is important because we get the compiled CSS from this and inject it in Storybook so you can have global styles in all your stories without the need to duplicate this styles.
start
: runs the storybook, this is used when develop because of the live reloadingbuild
: builds your app as a web component and outputs a minified and a normal version to /dist
build:open
: builds your app and also runs a development server for viewing how your compiled component will look like