Choose your template (regular/monorepo)
Clone it with degit:
npx degit YogliB/svelte-component-template my-new-component
or
npx degit "YogliB/svelte-component-template#monorepo" my-new-component
cd
into the folder and install the node_modules
:cd my-new-component
git init
npm install
or:
yarn
npm run bootstrap
or:
yarn bootstrap
npm init
, to configure the project.Your component's source code lives in src/components/[MyComponent].svelte
.
npm run dev
Edit a component file in src/components
, save it and watch the magic happens.
Make sure your component is exported in src/components/index.js
.
Make sure your component is imported and nested in src/App.svelte
, so you can preview and test it.
Navigate to localhost:5000 to see your components live.
Your package.json has a "svelte"
field pointing to src/components/index.js
, which allows Svelte apps to import the source code directly, if they are using a bundler plugin like rollup-plugin-svelte or svelte-loader (where resolve.mainFields
in your webpack config includes "svelte"
).
This template uses svelte-preprocess in order to integrate PostCSS auto-prefixing capabilities & Babel's transpiling capabilities into the build process.
PostCSS
uses browserlist under the hood, in order to "know" what css to prefix.
The browserlist
configuration is located inside the package.json
.
This template comes with the svelte-preprocess by default, which simplifies the use of preprocessors in components.
Getting Started with svelte-preprocess.
sveltePreprocessConfig
variable in ./preprocess.js
This template uses Cypress & testing-library for testing.
It is highly recommended going through their docs if you intend on testing your components.
You can witness a simple example by running npm run cy:open
.
index.js
file for?It's for Svelte to be able to import multiple components from a single source.
For instance, it lets the user do:
import { MyComponent, MyOtherComponent } from 'my-component-library';
Instead of:
import MyComponent from 'my-component-library/components/MyComponent.svelte';
import MyOtherComponent from 'my-component-library/components/MyOtherComponent';
There are a few options to do this:
@import url('https://unpkg.com/@scope/package/main.min.css');