-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.custom.config.js
50 lines (47 loc) · 1.41 KB
/
webpack.custom.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
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i
const zopfli = require('@gfx/zopfli')
const BrotliPlugin = require('brotli-webpack-plugin')
const dynamicPluginList = [
new CompressionWebpackPlugin({
algorithm(input, compressionOptions, callback) {
return zopfli.gzip(input, compressionOptions, callback)
},
compressionOptions: {
numiterations: 15
},
minRatio: 0.99,
test: productionGzipExtensions
}),
new BrotliPlugin({
test: productionGzipExtensions,
minRatio: 0.99
})
]
module.exports = (env, argv) => {
let filename = env.filename;
let targetFilename = encodeURIComponent(filename.substring(filename.lastIndexOf('/')+1));
targetFilename = targetFilename.substring(0, targetFilename.lastIndexOf('.'));
return {
entry: './' + filename,
output: {
filename: './' + targetFilename + (argv.mode === 'production' ? '.min' : '') + '.js',
library: targetFilename,
chunkFormat: 'array-push',
},
mode: argv.mode === 'production' ? 'production' : 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader',
],
},
]
},
target: ['es5'],
plugins: dynamicPluginList,
};
};