Commit 0b5f6ba8 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Initial commit

"presets": [
"plugins": [
"legacy": true
"proposal": "minimal"
"env": {
"node": true
"globals": {
"Promise": true,
"Set": true
"parser": "babel-eslint",
"plugins": [
"rules": {
"comma-dangle": [2, "always-multiline"],
"max-len": [2, 120, 2],
"no-undef": 2,
"no-unused-expressions": 2,
"no-unused-vars": 2,
"no-use-before-define": [2, "nofunc"],
"quotes": [2, "double", "avoid-escape"],
"semi": [2, "never"],
"strict": 0
# sapper-template
The default [Sapper]( template. To clone it and get started:
npx degit sveltejs/sapper-template my-app
cd my-app
npm install # or yarn!
npm run dev
Open up [localhost:3000](http://localhost:3000) and start clicking around.
Consult []( for help getting started.
## Structure
Sapper expects to find three directories in the root of your project — `app`, `assets` and `routes`.
### app
The [app](app) directory contains the entry points for your app — `client.js`, `server.js` and (optionally) a `service-worker.js` — along with your main `App.html` component.
### assets
The [assets](assets) directory contains any static assets that should be available. These are served using [serve-static](
In your [service-worker.js](app/service-worker.js) file, you can import these as `assets` from the generated manifest...
import { assets } from './manifest/service-worker.js';
``` that you can cache them (though you can choose not to, for example if you don't want to cache very large files).
### 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 `.html` 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 `routes/about.html` corresponds to the `/about` route. A file called `routes/blog/[slug].html` corresponds to the `/blog/:slug` route, in which case `params.slug` is available to the route
* The file `routes/index.html` (or `routes/index.js`) corresponds to the root of your app. `routes/about/index.html` is treated the same as `routes/about.html`.
* 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 `routes/_helpers/datetime.js` and it would *not* create a `/_helpers/datetime` route
## Webpack config
Sapper uses webpack to provide code-splitting, dynamic imports and hot module reloading, as well as compiling your Svelte components. As long as you don't do anything daft, you can edit the configuration files to add whatever loaders and 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 hot module replacement, and activate the appropriate webpack 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
## 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 webpack doesn't treat the package as an *external dependency*. You can either modify the `externals` option in [webpack/server.config.js](webpack/server.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:
yarn add -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](
import "bootstrap"
import { init } from "sapper/runtime.js"
import { manifest } from "./manifest/client.js"
target: document.querySelector("#sapper"),
import { validateConfig } from "./server-validators"
const config = {
title: "D-FIH",
const [validConfig, error] = validateConfig(config)
if (error !== null) {
`Error in configuration:\n${JSON.stringify(validConfig, null, 2)}\nError:\n${JSON.stringify(error, null, 2)}`
export default validConfig
@import "node_modules/bootstrap/scss/bootstrap";
/* Cf */
@font-face {
font-family: "Material Icons";
font-style: normal;
font-weight: 400;
src: url(/material-design-icons/iconfont/MaterialIcons-Regular.eot); /* For IE6-8 */
src: local("Material Icons"), local("MaterialIcons-Regular"),
url(/material-design-icons/iconfont/MaterialIcons-Regular.woff2) format("woff2"),
url(/material-design-icons/iconfont/MaterialIcons-Regular.woff) format("woff"),
url(/material-design-icons/iconfont/MaterialIcons-Regular.ttf) format("truetype");
.material-icons {
font-family: "Material Icons";
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: "liga";
// Server-side validators
export function validateConfig(config) {
if (config === null || config === undefined) {
return [config, "Missing config"]
if (typeof config !== "object") {
return [config, `Expected an object got "${typeof config}"`]
config = { ...config }
const errors = {}
const remainingKeys = new Set(Object.keys(config))
const key = "title"
if (remainingKeys.delete(key)) {
let value = config[key]
if (typeof value !== "string") {
errors[key] = `Expected a string got "${typeof value}"`
} else {
value = value.trim()
if (!value) {
errors[key] = "Expected a non empty string"
} else {
config[key] = value
} else {
errors[key] = "Missing item"
for (let key of remainingKeys) {
errors[key] = "Unexpected item"
return [config, Object.keys(errors).length === 0 ? null : errors]
import bodyParser from "body-parser"
import compression from "compression"
import path from "path"
import polka from "polka"
import sapper from "sapper"
import sirv from "sirv"
import "./global.scss"
import { manifest } from "./manifest/server.js"
const { PORT, NODE_ENV } = process.env
const dev = NODE_ENV === "development"
polka() // You can also use Express
.use(compression({ threshold: 0 }), sirv("assets", { dev }), bodyParser.json(), sapper({ manifest }))
.catch(error => {
console.log(error.stack || error)
import { timestamp, assets, shell, routes } from "./manifest/service-worker.js"
const ASSETS = `cache${timestamp}`
// `shell` is an array of all the files generated by webpack,
// `assets` is an array of everything in the `assets` directory
const to_cache = shell.concat(assets)
const cached = new Set(to_cache)
self.addEventListener("install", event => {
.then(cache => cache.addAll(to_cache))
.then(() => {
self.addEventListener("activate", event => {
caches.keys().then(async keys => {
// delete old caches
for (const key of keys) {
if (key !== ASSETS) await caches.delete(key)
self.addEventListener("fetch", event => {
if (event.request.method !== "GET") return
const url = new URL(event.request.url)
// don't try to handle e.g. data: URIs
if (!url.protocol.startsWith("http")) return
// ignore dev server requests
if (url.hostname === self.location.hostname && url.port !== self.location.port) return
// always serve assets and webpack-generated files from cache
if ( === && cached.has(url.pathname)) {
// for pages, you might want to serve a shell `index.html` file,
// which Sapper has generated for you. It's not right for every
// app, but if it's right for yours then uncomment this section
if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) {
// for everything else, try the network first, falling back to
// cache if the user is offline. (If the pages never change, you
// might prefer a cache-first approach to a network-first one.)
event.respondWith(`offline${timestamp}`).then(async cache => {
try {
if (event.request.cache === "only-if-cache") {
// workaround Chrome devtools bug
event.request.mode = "same-origin"
const response = await fetch(event.request)
cache.put(event.request, response.clone())
return response
} catch (err) {
const response = await cache.match(event.request)
if (response) return response
throw err
<!doctype html>
<html lang="fr">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#aa1e1e">
<link rel="stylesheet" href="server.css">
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/png" href="favicon.png">
<!-- Sapper generates a <style> tag containing critical CSS
for the current page. CSS for the rest of the app is
lazily loaded when it precaches secondary pages -->
<!-- This contains the contents of the <svelte:head> component, if
the current page has one -->
<!-- The application will be rendered inside this element,
because `app/client.js` references it -->
<div id="sapper">%sapper.html%</div>
<!-- Sapper creates a <script> tag containing `app/client.js`
and anything else it needs to hydrate the app and
initialise the router -->
"background_color": "#ffffff",
"description": "TODO",
"display": "minimal-ui",
"icons": [
"src": "svelte-logo-192.png",
"sizes": "192x192",
"type": "image/png"
"src": "svelte-logo-512.png",
"sizes": "512x512",
"type": "image/png"
"lang": "fr",
"name": "D-FIH",
"short_name": "D-FIH",
"start_url": "/?utm_source=homescreen",
"theme_color": "#aa1e1e"
<nav class="bg-secondary fixed-top navbar navbar-dark navbar-expand-lg">
<a class="navbar-brand" href="/" rel="prefetch">{config.title}</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Basculer l'affichage de la navigation">
<span class="navbar-toggler-icon"></span>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="ml-auto navbar-nav">
{#if segment === undefined}
<li class="nav-item active">
<a class="nav-link" href="." rel="prefetch">home <span class="sr-only">(actuel)</span></a>
<li class="nav-item">
<a class="nav-link" href="." rel="prefetch">home</a>
{#if segment === "about"}
<li class="nav-item active">
<a class="nav-link" href="about" rel="prefetch">about <span class="sr-only">(actuel)</span></a>
<li class="nav-item">
<a class="nav-link" href="about" rel="prefetch">about</a>
<div style="height: 64px;"></div>
import config from "../app/config"
export default {
helpers: {
This diff is collapsed.
"name": "d-fih-ui",
"description": "TODO",
"version": "0.0.1",
"license": "AGPL-3.0-or-later",
"repository": "",
"scripts": {
"dev": "sapper dev",
"build": "sapper build",
"export": "sapper export",
"start": "node build"
"dependencies": {
"body-parser": "^1.18.3",
"bootstrap": "^4.1.3",
"compression": "^1.7.3",
"jquery": "^3.3.1",
"material-design-icons": "^3.0.1",
"polka": "^0.4.0",
"popper.js": "^1.14.4",
"sapper": "^0.17.1",
"sirv": "^0.2.0",
"url-resolve": "^1.0.0"
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"autoprefixer": "^9.1.3",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.0.0-beta.0",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^1.0.0",
"eslint": "^5.4.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-html": "^4.0.5",
"mini-css-extract-plugin": "^0.4.2",
"node-sass": "^4.9.3",
"npm-run-all": "^4.1.2",
"postcss-loader": "^3.0.0",
"precss": "^3.1.2",
"sass-loader": "^7.1.0",
"svelte": "^2.13.2",
"svelte-loader": "^2.11.0",
"webpack": "^4.17.1"
<Nav segment="error"/>
<main class="container-fluid">
h1, p {
margin: 0 auto;
h1 {
font-size: 2.8em;
font-weight: 700;
margin: 0 0 0.5em 0;
p {
margin: 1em auto;
@media (min-width: 480px) {
h1 {
font-size: 4em;
export default {
components: {
Nav: "../components/Nav.html",
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment