mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-21 22:15:00 +00:00
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,4 +4,5 @@ node_modules
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
cypress/screenshots
|
cypress/screenshots
|
||||||
templates/.*
|
templates/.*
|
||||||
dist
|
dist
|
||||||
|
app/manifest
|
||||||
7
app/client.js
Normal file
7
app/client.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { init } from 'sapper/runtime.js';
|
||||||
|
import { routes } from './manifest/client.js';
|
||||||
|
|
||||||
|
// `routes` is an array of route objects injected by Sapper
|
||||||
|
init(document.querySelector('#sapper'), routes);
|
||||||
|
|
||||||
|
if (module.hot) module.hot.accept();
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const app = require('express')();
|
import express from 'express';
|
||||||
const compression = require('compression');
|
import compression from 'compression';
|
||||||
const sapper = require('sapper');
|
import sapper from 'sapper';
|
||||||
const static = require('serve-static');
|
import serve from 'serve-static';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
import { routes } from './manifest/server.js';
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
const { PORT = 3000 } = process.env;
|
const { PORT = 3000 } = process.env;
|
||||||
|
|
||||||
// this allows us to do e.g. `fetch('/api/blog-posts')` on the server
|
// this allows us to do e.g. `fetch('/api/blog-posts')` on the server
|
||||||
const fetch = require('node-fetch');
|
|
||||||
global.fetch = (url, opts) => {
|
global.fetch = (url, opts) => {
|
||||||
if (url[0] === '/') url = `http://localhost:${PORT}${url}`;
|
if (url[0] === '/') url = `http://localhost:${PORT}${url}`;
|
||||||
return fetch(url, opts);
|
return fetch(url, opts);
|
||||||
@@ -15,9 +18,11 @@ global.fetch = (url, opts) => {
|
|||||||
|
|
||||||
app.use(compression({ threshold: 0 }));
|
app.use(compression({ threshold: 0 }));
|
||||||
|
|
||||||
app.use(static('assets'));
|
app.use(serve('assets'));
|
||||||
|
|
||||||
app.use(sapper());
|
app.use(sapper({
|
||||||
|
routes
|
||||||
|
}));
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`listening on port ${PORT}`);
|
console.log(`listening on port ${PORT}`);
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
const timestamp = '__timestamp__';
|
import { timestamp, assets, shell, routes } from './manifest/service-worker.js';
|
||||||
|
|
||||||
const ASSETS = `cache${timestamp}`;
|
const ASSETS = `cache${timestamp}`;
|
||||||
|
|
||||||
// `shell` is an array of all the files generated by webpack,
|
// `shell` is an array of all the files generated by webpack,
|
||||||
// `assets` is an array of everything in the `assets` directory
|
// `assets` is an array of everything in the `assets` directory
|
||||||
const to_cache = __shell__.concat(__assets__);
|
const to_cache = shell.concat(assets);
|
||||||
const cached = new Set(to_cache);
|
const cached = new Set(to_cache);
|
||||||
|
|
||||||
// `routes` is an array of `{ pattern: RegExp }` objects that
|
|
||||||
// match the pages in your app
|
|
||||||
const routes = __routes__;
|
|
||||||
|
|
||||||
self.addEventListener('install', event => {
|
self.addEventListener('install', event => {
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
caches
|
caches
|
||||||
@@ -10,9 +10,9 @@
|
|||||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
<link rel='icon' type='image/png' href='/favicon.png'>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
// if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/service-worker.js');
|
// navigator.serviceWorker.register('/service-worker.js');
|
||||||
}
|
// }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Sapper generates a <style> tag containing critical CSS
|
<!-- Sapper generates a <style> tag containing critical CSS
|
||||||
@@ -3,9 +3,10 @@
|
|||||||
"description": "TODO",
|
"description": "TODO",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node server.js",
|
"dev": "sapper dev",
|
||||||
"build": "sapper build",
|
"build": "sapper build",
|
||||||
"start": "cross-env NODE_ENV=production node server.js",
|
"export": "sapper export",
|
||||||
|
"start": "cross-env NODE_ENV=production node .sapper/server.js",
|
||||||
"cy:run": "cypress run",
|
"cy:run": "cypress run",
|
||||||
"cy:open": "cypress open",
|
"cy:open": "cypress open",
|
||||||
"test": "run-p --race dev cy:run"
|
"test": "run-p --race dev cy:run"
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
"node-fetch": "^2.0.0",
|
"node-fetch": "^2.0.0",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
"sapper": "^0.6.3",
|
"sapper": "^0.6.4",
|
||||||
"serve-static": "^1.13.1",
|
"serve-static": "^1.13.1",
|
||||||
"style-loader": "^0.20.1",
|
"style-loader": "^0.20.1",
|
||||||
"svelte": "^1.51.1",
|
"svelte": "^1.51.1",
|
||||||
|
|||||||
43
routes/4xx.html
Normal file
43
routes/4xx.html
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<:Head>
|
||||||
|
<title>Not found</title>
|
||||||
|
</:Head>
|
||||||
|
|
||||||
|
<Layout page='home'>
|
||||||
|
<h1>Not found</h1>
|
||||||
|
|
||||||
|
<p>Please check the URL</p>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h1, p {
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.8em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0 0 0.5em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 1em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 480px) {
|
||||||
|
h1 {
|
||||||
|
font-size: 4em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Layout from './_components/Layout.html';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
Layout
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
41
routes/5xx.html
Normal file
41
routes/5xx.html
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<:Head>
|
||||||
|
<title>Internal server error</title>
|
||||||
|
</:Head>
|
||||||
|
|
||||||
|
<Layout page='home'>
|
||||||
|
<h1>Internal server error</h1>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h1, p {
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2.8em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0 0 0.5em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 1em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 480px) {
|
||||||
|
h1 {
|
||||||
|
font-size: 4em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Layout from './_components/Layout.html';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
Layout
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset='utf-8'>
|
|
||||||
<meta name='viewport' content='width=device-width'>
|
|
||||||
<meta name='theme-color' content='#aa1e1e'>
|
|
||||||
|
|
||||||
<link rel='manifest' href='/manifest.json'>
|
|
||||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
|
||||||
|
|
||||||
<!-- %sapper.status% is the HTTP status code, e.g. 404 -->
|
|
||||||
<title>%sapper.status%</title>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
max-width: 800px;
|
|
||||||
padding: 1em;
|
|
||||||
margin: 0 auto;
|
|
||||||
font-family: Roboto, -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
|
||||||
background-color: #f4f4f4;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: rgb(170,30,30);
|
|
||||||
border-bottom: 1px solid #aaa;
|
|
||||||
padding: 0 0 0.5em 0;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
font-family: Menlo, monospace;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.2;
|
|
||||||
overflow-x: auto;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>%sapper.title%</h1>
|
|
||||||
<p>Could not %sapper.method% %sapper.url%</p>
|
|
||||||
|
|
||||||
%sapper.scripts%
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset='utf-8'>
|
|
||||||
<meta name='viewport' content='width=device-width'>
|
|
||||||
<meta name='theme-color' content='#aa1e1e'>
|
|
||||||
|
|
||||||
<link rel='manifest' href='/manifest.json'>
|
|
||||||
<link rel='icon' type='image/png' href='/favicon.png'>
|
|
||||||
|
|
||||||
<title>%sapper.status%</title>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
max-width: 800px;
|
|
||||||
padding: 1em;
|
|
||||||
margin: 0 auto;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: rgb(170,30,30);
|
|
||||||
border-bottom: 1px solid #aaa;
|
|
||||||
padding: 0 0 0.5em 0;
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre {
|
|
||||||
font-family: Menlo, monospace;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.2;
|
|
||||||
overflow-x: auto;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stack {
|
|
||||||
font-size: 12px;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>%sapper.title%</h1>
|
|
||||||
<pre>%sapper.error%</pre>
|
|
||||||
<pre class='stack'>%sapper.stack%</pre>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import { init } from 'sapper/runtime.js';
|
|
||||||
|
|
||||||
// `routes` is an array of route objects injected by Sapper
|
|
||||||
init(document.querySelector('#sapper'), __routes__);
|
|
||||||
17
webpack/service-worker.config.js
Normal file
17
webpack/service-worker.config.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const config = require('sapper/webpack/config.js');
|
||||||
|
const webpack = require('webpack');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: {
|
||||||
|
'service-worker': './app/service-worker.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.resolve(`.sapper`),
|
||||||
|
filename: '[name].js',
|
||||||
|
chunkFilename: '[name].[id].[hash].js'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
!config.dev && new webpack.optimize.ModuleConcatenationPlugin()
|
||||||
|
].filter(Boolean)
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user