Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7f242e6

Browse files
committedMar 20, 2019
Serviceworker now properly loads
1 parent 88cb7cc commit 7f242e6

File tree

2 files changed

+100
-85
lines changed

2 files changed

+100
-85
lines changed
 

‎packages/web/src/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
return;
2424
}
2525
document.body.style.background = bg;
26-
})();
26+
})();
27+
28+
// Check that service workers are registered
29+
if ('serviceWorker' in navigator) {
30+
// Use the window load event to keep the page load performant
31+
window.addEventListener('load', () => {
32+
navigator.serviceWorker.register('/service-worker.js');
33+
});
34+
}
2735
</script>
2836
</body>
2937

‎scripts/webpack.client.config.js

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,96 @@
1-
const webpack = require("webpack");
2-
const path = require("path");
3-
const merge = require("webpack-merge");
4-
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5-
const PreloadWebpackPlugin = require("preload-webpack-plugin");
6-
const HtmlWebpackPlugin = require("html-webpack-plugin");
7-
const WebpackPwaManifest = require('webpack-pwa-manifest')
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const merge = require('webpack-merge');
4+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5+
const PreloadWebpackPlugin = require('preload-webpack-plugin');
6+
const HtmlWebpackPlugin = require('html-webpack-plugin');
7+
const WebpackPwaManifest = require('webpack-pwa-manifest');
88
const { GenerateSW } = require('workbox-webpack-plugin');
99

1010
// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
1111

12-
const root = path.join(__dirname, "..");
13-
const prod = process.env.NODE_ENV === "production";
12+
const root = path.join(__dirname, '..');
13+
const prod = process.env.NODE_ENV === 'production';
1414

15-
module.exports = (options = {}) => merge(
16-
require("./webpack.general.config")(options), {
17-
devtool: prod ? "source-map" : "cheap-module-eval-source-map",
18-
mode: prod ? "production" : "development",
19-
entry: prod ? options.entry : [
20-
"webpack-hot-middleware/client?reload=true&quiet=true",
21-
options.entry,
22-
],
23-
module: {
24-
rules: [{
25-
test: /\.s?css$/,
26-
// This is required otherwise it'll fail to resolve CSS in common.
27-
include: root,
28-
use: [{
29-
loader: MiniCssExtractPlugin.loader,
30-
}, {
31-
loader: "css-loader",
32-
}, {
33-
loader: "sass-loader",
34-
}],
35-
}, {
36-
test: /\.(svg|png|ttf|woff|eot|woff2)$/,
37-
use: [{
38-
loader: "file-loader",
39-
options: {
40-
name: "[path][name].[ext]",
41-
},
42-
}],
43-
}],
44-
},
45-
plugins: [
46-
new MiniCssExtractPlugin({
47-
filename: "[name].css",
48-
chunkFilename: "[id].css",
49-
}),
50-
new HtmlWebpackPlugin({
51-
template: options.template,
52-
}),
53-
new PreloadWebpackPlugin({
54-
rel: "preload",
55-
as: "script",
56-
}),
57-
new WebpackPwaManifest({
58-
name: "Coder",
59-
short_name: "Coder",
60-
description: "Run VS Code on a remote server",
61-
background_color: "#303030",
62-
icons: [
15+
module.exports = (options = {}) =>
16+
merge(require('./webpack.general.config')(options), {
17+
devtool: prod ? 'source-map' : 'cheap-module-eval-source-map',
18+
mode: prod ? 'production' : 'development',
19+
entry: prod
20+
? options.entry
21+
: ['webpack-hot-middleware/client?reload=true&quiet=true', options.entry],
22+
module: {
23+
rules: [
6324
{
64-
src: path.resolve("./assets/logo.png"),
65-
sizes: [96, 128, 192, 256, 384]
25+
test: /\.s?css$/,
26+
// This is required otherwise it'll fail to resolve CSS in common.
27+
include: root,
28+
use: [
29+
{
30+
loader: MiniCssExtractPlugin.loader
31+
},
32+
{
33+
loader: 'css-loader'
34+
},
35+
{
36+
loader: 'sass-loader'
37+
}
38+
]
39+
},
40+
{
41+
test: /\.(svg|png|ttf|woff|eot|woff2)$/,
42+
use: [
43+
{
44+
loader: 'file-loader',
45+
options: {
46+
name: '[path][name].[ext]'
47+
}
48+
}
49+
]
6650
}
6751
]
68-
}),
69-
].concat(prod ? [
70-
new GenerateSW({
71-
runtimeCaching: [{
72-
urlPattern: "",
73-
handler: 'StaleWhileRevalidate',
74-
options: {
75-
cacheName: 'code-server',
76-
expiration: {
77-
maxAgeSeconds: 86400,
78-
},
79-
cacheableResponse: {
80-
statuses: [0, 200],
81-
},
82-
},
83-
}
84-
// Network first caching is also possible.
85-
/*{
52+
},
53+
plugins: [
54+
new MiniCssExtractPlugin({
55+
filename: '[name].css',
56+
chunkFilename: '[id].css'
57+
}),
58+
new HtmlWebpackPlugin({
59+
template: options.template
60+
}),
61+
new PreloadWebpackPlugin({
62+
rel: 'preload',
63+
as: 'script'
64+
}),
65+
new WebpackPwaManifest({
66+
name: 'Coder',
67+
short_name: 'Coder',
68+
description: 'Run VS Code on a remote server',
69+
background_color: '#303030',
70+
icons: [
71+
{
72+
src: path.resolve('./assets/logo.png'),
73+
sizes: [96, 128, 192, 256, 384]
74+
}
75+
]
76+
}),
77+
new GenerateSW({
78+
runtimeCaching: [
79+
{
80+
urlPattern: new RegExp('.*'),
81+
handler: 'StaleWhileRevalidate',
82+
options: {
83+
cacheName: 'code-server',
84+
expiration: {
85+
maxAgeSeconds: 86400
86+
},
87+
cacheableResponse: {
88+
statuses: [0, 200]
89+
}
90+
}
91+
}
92+
// Network first caching is also possible.
93+
/*{
8694
urlPattern: "",
8795
handler: 'NetworkFirst',
8896
options: {
@@ -95,10 +103,9 @@ module.exports = (options = {}) => merge(
95103
statuses: [0, 200],
96104
},
97105
},
98-
}*/]
99-
}),
100-
] : [
101-
new webpack.HotModuleReplacementPlugin(),
102-
]),
103-
target: "web",
104-
});
106+
}*/
107+
]
108+
})
109+
].concat(prod ? [] : [new webpack.HotModuleReplacementPlugin()]),
110+
target: 'web'
111+
});

0 commit comments

Comments
 (0)
Please sign in to comment.