Skip to content

Commit e0a1d87

Browse files
committed
📝 Improve usage docs and add integration guide
Related to: #1
1 parent 42d4ccc commit e0a1d87

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,33 @@ TODO:
1111
- [x] SCSS and Sass support
1212
- [x] Svelte transitions support
1313

14-
## How to use?
14+
## Usage
15+
16+
### How to modify the template?
1517

1618
Clone it with [degit](https://github.com/Rich-Harris/degit):
1719

18-
```sh
20+
```bash
1921
npx degit redradix/svelte-custom-element-template my-new-component
2022
cd my-new-component
21-
npm install # or yarn
23+
24+
yarn install # or npm
25+
yarn start
2226
```
2327

24-
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](./scripts/build.js))
28+
Start making your own modifications watching changes in Storybook.
2529

26-
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.
30+
### How to integrate the component in your project?
31+
32+
1. Build the component using `yarn build`
33+
2. (Optional) Create a `public` folder
34+
3. (Optional) Create an `public/index.html` file
35+
4. Copy the built component inside a `vendor` folder (accesible from `index.html`)
36+
5. Import the component from the HTML using the `defer` attribute
37+
```html
38+
<script defer src="vendor/svelte-custom-element.0.1.0.min.js"></script>
39+
```
40+
6. Open the `index.html` and enjoy the web component
2741

2842
## Why?
2943
Building 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.
@@ -35,6 +49,12 @@ Svelte current limitations:
3549
* [Transitions in custom Elements](https://github.com/sveltejs/svelte/issues/1825)
3650
* [Context API doesn't work for custom elements](https://github.com/sveltejs/svelte/issues/3422)
3751

52+
## How does this template work?
53+
54+
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](./scripts/build.js))
55+
56+
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.
57+
3858
## Available scripts
3959

4060
* `start`: runs the storybook, this is used when develop because of the live reloading

0 commit comments

Comments
 (0)