My site
Go to file
2024-10-31 09:11:04 +00:00
_pages portfoliooooo 2024-10-23 16:01:48 +02:00
_posts/blog broadcasts on index page 2024-10-03 20:59:01 +02:00
_projects order projects 2024-09-27 13:34:07 +02:00
.gitea/workflows fuckit 2024-09-18 16:30:16 +02:00
.zellij remove old svelte web source 2024-09-30 21:13:20 +02:00
docs remove old svelte web source 2024-09-30 21:13:20 +02:00
src animated logo in portfolio 2024-10-25 20:29:49 +02:00
static animated logo in portfolio 2024-10-25 20:29:49 +02:00
styles animated logo in portfolio 2024-10-25 20:29:49 +02:00
templates perfected the animation 2024-10-25 21:58:53 +02:00
.gitattributes Add egg-fetcher demo 2022-06-28 09:32:15 +02:00
.gitignore remove old svelte web source 2024-09-30 21:13:20 +02:00
.lfsconfig-netlify remove old svelte web source 2024-09-30 21:13:20 +02:00
.npmrc fix legacy peer deps 2023-02-02 20:00:03 +01:00
.nvmrc Change node version to always be latest LTS 2023-02-02 20:05:07 +01:00
.prettierignore Svelte kit transition 2021-04-24 18:24:17 +02:00
.prettierrc Svelte kit transition 2021-04-24 18:24:17 +02:00
askama.toml remove old svelte web source 2024-09-30 21:13:20 +02:00
Caddyfile-preview 404 page 2024-10-07 10:14:32 +02:00
Cargo.toml Update Rust crate pulldown-cmark to 0.12 2024-10-31 09:11:04 +00:00
email-signature.html Change email signature 2022-03-17 18:01:09 +01:00
justfile portfoliooooo 2024-10-23 16:01:48 +02:00
LICENSE Add Licenses 2022-05-07 21:12:26 +02:00
missing_lfs_files.txt remove old svelte web source 2024-09-30 21:13:20 +02:00
README.md Sapper bootstrap 2019-07-12 09:49:03 +02:00
renovate.json Add renovate.json 2024-10-31 09:06:39 +00:00
robots.txt broadcasts and 404 errors 2024-10-02 15:32:40 +02:00
tailwind.config.js remove old svelte web source 2024-09-30 21:13:20 +02:00
test-animate.svg portfoliooooo 2024-10-23 16:01:48 +02:00

sapper-template

The default Sapper template, with branches for Rollup and webpack. To clone it and get started:

# for Rollup
npx degit "sveltejs/sapper-template#rollup" my-app
# for webpack
npx degit "sveltejs/sapper-template#webpack" my-app
cd my-app
npm install # or yarn!
npm run dev

Open up localhost:3000 and start clicking around.

Consult sapper.svelte.dev for help getting started.

Structure

Sapper expects to find two directories in the root of your project — src and static.

src

The src directory contains the entry points for your app — client.js, server.js and (optionally) a service-worker.js — along with a template.html file and a routes directory.

src/routes

This is the heart of your Sapper app. There are two kinds of routes — pages, and server routes.

Pages are Svelte components written in .svelte files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)

Server routes are modules written in .js files, that export functions corresponding to HTTP methods. Each function receives Express request and response objects as arguments, plus a next function. This is useful for creating a JSON API, for example.

There are three simple rules for naming the files that define your routes:

  • A file called src/routes/about.svelte corresponds to the /about route. A file called src/routes/blog/[slug].svelte corresponds to the /blog/:slug route, in which case params.slug is available to the route
  • The file src/routes/index.svelte (or src/routes/index.js) corresponds to the root of your app. src/routes/about/index.svelte is treated the same as src/routes/about.svelte.
  • Files and directories with a leading underscore do not create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called src/routes/_helpers/datetime.js and it would not create a /_helpers/datetime route

static

The static directory contains any static assets that should be available. These are served using sirv.

In your service-worker.js file, you can import these as files from the generated manifest...

import { files } from '@sapper/service-worker';

...so that you can cache them (though you can choose not to, for example if you don't want to cache very large files).

Bundler config

Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.

Production mode and deployment

To start a production version of your app, run npm run build && npm start. This will disable live reloading, and activate the appropriate bundler plugins.

You can deploy your application to any environment that supports Node 8 or above. As an example, to deploy to Now, run these commands:

npm install -g now
now

Using external components

When using Svelte components installed from npm, such as @sveltejs/svelte-virtual-list, Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.

Because of that, it's essential that the bundler doesn't treat the package as an external dependency. You can either modify the external option under server in rollup.config.js or the externals option in webpack.config.js, or simply install the package to devDependencies rather than dependencies, which will cause it to get bundled (and therefore compiled) with your app:

npm install -D @sveltejs/svelte-virtual-list

Bugs and feedback

Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the Sapper issue tracker.