Svelte TypeScript Template
This template includes:
- Transpiling ES6 and TypeScript with Babel
- Testing with Jest and Svelte-Testing-Library
- Linting/Formatting with Eslint and Prettier
Things that aren't TypeScript:
- Svelte doesn't work with TypeScript in
.sveltefiles yet. This setup just lets you use typescript for all of your stores and other non-component files.
If you don't want to use TypeScript
This uses Babel to compile the ts files, so if you just want babel for ES6,
you can remove references to TypeScript in
Create a new project
To create a new project based on this template using degit:
npx degit will-wow/svelte-typescript-template cd svelte-app
Note that you will need to have Node.js installed.
Install the dependencies...
cd svelte-app yarn install
...then start Rollup:
Navigate to localhost:5000. You should see your app running. Edit a component file in
src and save it. The page will automatically update with your changes.
To run the test suite
To run the tests with watchers
yarn test --watch
To generate a coverage report
yarn test --coverage open coverage/lcov-report/index.html
Importing TS files
.svelte files, you should include the
.ts extension when importing TypeScript files.
For some reason Jest won't follow the import otherwise.
Note on caching:
jest-transform-svelte seems to have an issue with caching. If you find
that a test is using an old version of an imported file, try
yarn jest --clearCache, and then re-run
Deploying to the web
deploy-surge script in
package.json with your surge domain.