Home

Awesome

Svelte TypeScript Template

This is a project template for Svelte 3 apps. It lives at github.com/will-wow/svelte-typescript-template.

This template includes:

Things that aren't TypeScript:

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 package.json, .babelrc, and .eslintrc.

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.

Get started

Install the dependencies...

cd svelte-app
yarn install

...then start Rollup:

yarn dev

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.

Testing

To run the test suite

yarn test

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

In your .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 yarn test.

Deploying to the web

With surge

Update the deploy-surge script in package.json with your surge domain.

yarn deploy