-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.js
143 lines (140 loc) · 3.78 KB
/
webpack.prod.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const { resolve } = require('path')
const { smart } = require('webpack-merge')
const { GenerateSW, InjectManifest } = require('workbox-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin') // https://github.com/terser-js/terser#minify-options
const baseConfig = require('./webpack.config')
const ssrMode = process.argv && process.argv.includes('--ssr')
const excludeVendorModule = []
const clientProductionConfig = smart(baseConfig(), {
devtool: false,
plugins: [
new GenerateSW({
swDest: 'sw.js',
importsDirectory: 'js',
// managed outside of webpack
// globDirectory: 'https://aaaaa.com/images/',
// globPatterns: ['https://aaaaa.com/page/*.{html,js,css}', 'https://aaaaa.com/images/*.{jpg,jpeg,png,gif,webp,svg}'],
// globIgnores: ['https://api.aaa.com/**/*'],
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: /\.html/,
handler: 'NetworkFirst',
options: {
cacheName: 'html',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 10
}
}
},
{
urlPattern: /\.js/,
handler: 'NetworkFirst',
options: {
cacheName: 'js',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 2
}
}
},
{
urlPattern: /\.(png|svg|woff|ttf|eot|json)/,
handler: 'CacheFirst',
options: {
cacheName: 'assets',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 7
}
}
},
{
urlPattern: new RegExp('https://hacker-news.firebaseio.com/v0/'),
handler: 'CacheFirst',
options: {
cacheName: 'hnApi',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 3
}
}
}
]
})
],
optimization: {
namedModules: true,
namedChunks: true,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
extractComments: 'all',
terserOptions: {
compress: {
arrows: true,
drop_console: true,
booleans: true
},
sourceMap: true,
ecma: 5, // specify one of: 5, 6, 7 or 8
keep_classnames: false,
keep_fnames: false,
module: true,
output: null,
ie8: false,
nameCache: null, // or specify a name cache object
safari10: false,
toplevel: true,
warnings: false
}
})
],
minimize: true,
splitChunks: {
chunks: 'async',
minSize: 1000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
reactmodules: {
test: /[\\/]node_modules[\\/]react|styled/,
name: 'reactmodule',
priority: -10,
chunks: 'all'
},
vendors: {
test(mod, chunk) {
if (!/[\\/]node_modules[\\/]/.test(mod.resource)) {
return false
}
return (
excludeVendorModule.length === 0 ||
excludeVendorModule.some(
libname => mod.resource && mod.resource.includes(libname)
)
)
},
name: 'vendors',
priority: -16,
chunks: 'all'
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
}
})
module.exports = ssrMode
? [baseConfig(true), clientProductionConfig]
: clientProductionConfig