-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
63 lines (57 loc) · 1.8 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const CleanPlugin = require("clean-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const { STATIONS_FOR_TRAIN_LINE_URL, REAL_TIME_FOR_STATION } = require("./src/constants");
const filesToCopy = [
"./subway_map.pdf",
"./manifest.json",
"./robots.txt",
{ from: "./images", to: "images/" }
];
const DIST_DIRECTORY = "dist";
module.exports = {
entry: path.resolve(__dirname, "src/index.js"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[contenthash].js"
},
optimization: {
runtimeChunk: {
name: "runtime"
}
},
plugins: [
new CleanPlugin([DIST_DIRECTORY]),
new CopyPlugin(filesToCopy),
new HtmlPlugin({
template: path.resolve(__dirname, "./index.html"),
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyCSS: true,
minifyJS: true
}
}),
new WorkboxPlugin.GenerateSW({
swDest: "sw.js",
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: new RegExp(REAL_TIME_FOR_STATION),
handler: "networkFirst"
},
{
urlPattern: new RegExp(STATIONS_FOR_TRAIN_LINE_URL),
handler: "staleWhileRevalidate"
}
]
})
]
}