mirror of
https://github.com/kevin-DL/sapper-template.git
synced 2026-01-16 03:54:37 +00:00
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,5 +4,6 @@ node_modules
|
|||||||
yarn.lock
|
yarn.lock
|
||||||
cypress/screenshots
|
cypress/screenshots
|
||||||
templates/.*
|
templates/.*
|
||||||
dist
|
export
|
||||||
|
build
|
||||||
app/manifest
|
app/manifest
|
||||||
@@ -26,7 +26,7 @@ self.addEventListener('activate', event => {
|
|||||||
if (key !== ASSETS) await caches.delete(key);
|
if (key !== ASSETS) await caches.delete(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
await self.clients.claim();
|
self.clients.claim();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -37,8 +37,11 @@ self.addEventListener('fetch', event => {
|
|||||||
// don't try to handle e.g. data: URIs
|
// don't try to handle e.g. data: URIs
|
||||||
if (!url.protocol.startsWith('http')) return;
|
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
|
// always serve assets and webpack-generated files from cache
|
||||||
if (cached.has(url.pathname)) {
|
if (url.host === self.location.host && cached.has(url.pathname)) {
|
||||||
event.respondWith(caches.match(event.request));
|
event.respondWith(caches.match(event.request));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
12
package.json
12
package.json
@@ -6,7 +6,7 @@
|
|||||||
"dev": "sapper dev",
|
"dev": "sapper dev",
|
||||||
"build": "sapper build",
|
"build": "sapper build",
|
||||||
"export": "sapper export",
|
"export": "sapper export",
|
||||||
"start": "cross-env NODE_ENV=production node .sapper/server.js",
|
"start": "sapper start",
|
||||||
"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"
|
||||||
@@ -14,18 +14,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"compression": "^1.7.1",
|
"compression": "^1.7.1",
|
||||||
"cross-env": "^5.1.3",
|
"cross-env": "^5.1.3",
|
||||||
"css-loader": "^0.28.7",
|
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
"extract-text-webpack-plugin": "^3.0.2",
|
|
||||||
"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.7.0",
|
"sapper": "^0.8.1",
|
||||||
"serve-static": "^1.13.1",
|
"serve-static": "^1.13.1",
|
||||||
"style-loader": "^0.20.1",
|
"svelte": "^1.56.0",
|
||||||
"svelte": "^1.51.1",
|
|
||||||
"svelte-loader": "^2.3.3",
|
"svelte-loader": "^2.3.3",
|
||||||
"uglifyjs-webpack-plugin": "^1.1.5",
|
"webpack": "^4.1.0"
|
||||||
"webpack": "^3.10.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,15 @@
|
|||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
h1, p {
|
h1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2.8em;
|
font-size: 2.8em;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
margin: 0 0 0.5em 0;
|
margin: 0 0 0.5em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 1em auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 480px) {
|
@media (min-width: 480px) {
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 4em;
|
font-size: 4em;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<h1>Great success!</h1>
|
<h1>Great success!</h1>
|
||||||
|
|
||||||
<figure>
|
<figure>
|
||||||
<img src='/great-success.png'>
|
<img alt='Borat' src='/great-success.png'>
|
||||||
<figcaption>HIGH FIVE!</figcaption>
|
<figcaption>HIGH FIVE!</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const config = require('sapper/webpack/config.js');
|
const config = require('sapper/webpack/config.js');
|
||||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
|
||||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
|
||||||
|
|
||||||
const isDev = config.dev;
|
const mode = process.env.NODE_ENV;
|
||||||
|
const isDev = mode === 'development';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: config.client.entry(),
|
entry: config.client.entry(),
|
||||||
output: config.client.output(),
|
output: config.client.output(),
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.html']
|
extensions: ['.js', '.json', '.html']
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
@@ -20,40 +19,17 @@ module.exports = {
|
|||||||
loader: 'svelte-loader',
|
loader: 'svelte-loader',
|
||||||
options: {
|
options: {
|
||||||
hydratable: true,
|
hydratable: true,
|
||||||
emitCss: !isDev,
|
|
||||||
cascade: false,
|
cascade: false,
|
||||||
store: true
|
store: true,
|
||||||
|
hotReload: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
isDev && {
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
{ loader: 'style-loader' },
|
|
||||||
{ loader: 'css-loader' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
!isDev && {
|
|
||||||
test: /\.css$/,
|
|
||||||
use: ExtractTextPlugin.extract({
|
|
||||||
fallback: 'style-loader',
|
|
||||||
use: [{ loader: 'css-loader', options: { sourceMap:isDev } }]
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
].filter(Boolean)
|
]
|
||||||
},
|
},
|
||||||
|
mode,
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
isDev && new webpack.HotModuleReplacementPlugin()
|
||||||
minChunks: 2,
|
].filter(Boolean),
|
||||||
async: false,
|
|
||||||
children: true
|
|
||||||
})
|
|
||||||
].concat(isDev ? [
|
|
||||||
new webpack.HotModuleReplacementPlugin()
|
|
||||||
] : [
|
|
||||||
new ExtractTextPlugin('main.css'),
|
|
||||||
new webpack.optimize.ModuleConcatenationPlugin(),
|
|
||||||
new UglifyJSPlugin()
|
|
||||||
]).filter(Boolean),
|
|
||||||
devtool: isDev && 'inline-source-map'
|
devtool: isDev && 'inline-source-map'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
const config = require('sapper/webpack/config.js');
|
const config = require('sapper/webpack/config.js');
|
||||||
const webpack = require('webpack');
|
const pkg = require('../package.json');
|
||||||
const ExtractTextPlugin = require("extract-text-webpack-plugin");
|
|
||||||
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: config.server.entry(),
|
entry: config.server.entry(),
|
||||||
output: config.server.output(),
|
output: config.server.output(),
|
||||||
target: 'node',
|
target: 'node',
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.js', '.html']
|
extensions: ['.js', '.json', '.html']
|
||||||
},
|
},
|
||||||
|
externals: Object.keys(pkg.dependencies),
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
@@ -26,5 +25,9 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
mode: process.env.NODE_ENV,
|
||||||
|
performance: {
|
||||||
|
hints: false // it doesn't matter if server.js is large
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
const path = require('path');
|
|
||||||
const config = require('sapper/webpack/config.js');
|
const config = require('sapper/webpack/config.js');
|
||||||
const webpack = require('webpack');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: {
|
entry: config.serviceworker.entry(),
|
||||||
'service-worker': './app/service-worker.js'
|
output: config.serviceworker.output(),
|
||||||
},
|
mode: process.env.NODE_ENV
|
||||||
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