forked from webpack/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
81 lines (78 loc) · 2.04 KB
/
webpack.prod.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
69
70
71
72
73
74
75
76
77
78
79
80
81
// Import External Dependencies
const { merge } = require('webpack-merge');
const OptimizeCSSAssetsPlugin = require('css-minimizer-webpack-plugin');
const { GenerateSW } = require('workbox-webpack-plugin');
// Load Common Configuration
const common = require('./webpack.common.js');
// find [css, ico, svg] versioned (hashed) files emitted by SSG run
const hashedAssetsBySSGRun = require('./src/utilities/find-files-in-dist')(['.css', '.ico', '.svg']);
module.exports = env => merge(common(env), {
mode: 'production',
target: 'web',
cache: {
buildDependencies: {
config: [__filename],
}
},
entry: {
index: {
import: './index.jsx',
filename: 'index.bundle.js'
}
},
output: {
filename: '[name].[contenthash].js'
},
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /node_modules/,
chunks: 'initial',
enforce: true,
filename: 'vendor.bundle.js'
}
}
},
minimizer: [
'...',
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new GenerateSW({
skipWaiting: true,
clientsClaim: true,
swDest: 'sw.js',
exclude: [/icon_.*\.png/, /printable/, '/robots.txt', ...hashedAssetsBySSGRun],
additionalManifestEntries: [
{
url: '/app-shell/index.html',
revision: new Date().getTime().toString() // dirty hack
},
{
url: '/manifest.json',
revision: '1'
},
...hashedAssetsBySSGRun.map(url => ({
url: '/' + url, // prepend the publicPath
revision: null
}))
],
navigateFallback: '/app-shell/index.html',
runtimeCaching: [
{
urlPattern: /https:\/\/fonts\.gstatic\.com/, // cache google fonts for one year
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts',
expiration: {
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30
}
}
}
],
})
]
});