-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
62 lines (53 loc) · 1.65 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
process.env.NODE_ENV = 'production'
// node modules
const merge = require('webpack-merge')
// webpack plugins
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CriticalCssPlugin = require('critical-css-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const common = require('./webpack.common.js')
const settings = require('./webpack.settings.js')
// configurations
const configureCriticalCss = () => {
return settings.criticalCssConfig.pages.map((row) => {
const criticalSrc = settings.urls.critical + row.url
const criticalDest = settings.criticalCssConfig.base + row.template + settings.criticalCssConfig.suffix
let criticalWidth = settings.criticalCssConfig.criticalWidth
let criticalHeight = settings.criticalCssConfig.criticalHeight
// Handle Google AMP templates
if (row.template.indexOf(settings.criticalCssConfig.ampPrefix) !== -1) {
criticalWidth = settings.criticalCssConfig.ampCriticalWidth
criticalHeight = settings.criticalCssConfig.ampCriticalHeight
}
return new CriticalCssPlugin({
base: './',
src: criticalSrc,
dest: criticalDest,
extract: false,
inline: false,
minify: true,
width: criticalWidth,
height: criticalHeight
})
})
}
const configureTerser = () => {
return {
terserOptions: {
output: {
comments: false
},
compress: {
drop_console: true
}
}
}
}
module.exports = merge(common, {
plugins: [
new BundleAnalyzerPlugin()
].concat(configureCriticalCss()),
optimization: {
minimizer: [new TerserPlugin(configureTerser())]
}
})