-
Notifications
You must be signed in to change notification settings - Fork 52
/
webpack.config.js
68 lines (67 loc) · 1.7 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
64
65
66
67
68
const path = require("path");
const OfflinePlugin = require("offline-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = ({ appShell, output = "." } = {}) => ({
entry: appShell ? {
// App Shell has only a single entry point
// this entry point loads pages with import()
shell: "./app/shell.js"
} : {
// Page Shell requires an entry point per page
dashboard: "./app/dashboard.js",
login: "./app/login.js",
admin: "./app/admin.js"
},
output: {
path: path.resolve(__dirname, "dist", output),
filename: "[name]-[chunkhash].js",
chunkFilename: "[chunkhash].js"
},
module: {
rules: [
{
test: /\.html/,
use: "html-loader"
}
]
},
plugins: [
// Generate a HTML page per page
// This could be replace by some server logic or SSR
// For the Page Shell each HTML page need to reference the correct entry point
new HtmlWebpackPlugin({
filename: "dashboard.html",
chunks: !appShell && ["dashboard"]
}),
new HtmlWebpackPlugin({
filename: "login.html",
chunks: !appShell && ["login"]
}),
new HtmlWebpackPlugin({
filename: "admin.html",
chunks: !appShell && ["admin"]
}),
// Offline support
new OfflinePlugin({
caches: {
main: [
// These assets don't have a chunk hash.
// SW fetch them on every SW update.
"dashboard.html",
"login.html",
"admin.html"
],
additional: [
// All other assets have a chunk hash.
// SW only fetch them once.
// They'll have another name on change.
":rest:"
]
},
// To remove a warning about additional need to have hash
safeToUseOptionalCaches: true,
// "additional" section is fetch only once.
updateStrategy: "changed"
})
]
});