This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
93 lines (82 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
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
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const pkg = require('./package.json')
const entry = [
'@babel/polyfill',
'./src/index.js'
]
function createNonce (secret) {
const buf = Buffer.from(secret || '', 'ascii')
return `'${buf.toString('base64')}'`
}
const processCfg = {
version: pkg.version,
secret: pkg.secret
}
const config = {
'process.config': JSON.stringify(processCfg),
'process.nonce': createNonce(processCfg.secret),
'process.test': process.env.TEST
}
const output = {
filename: 'js/index.js',
path: `${__dirname}/static`
}
const plugins = [
new webpack.DefinePlugin(config)
]
const optimization = {}
const rules = [
{
test: /src\/(.*)\.json$/,
loader: 'json-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
query: {
presets: [
['@babel/preset-env', {
exclude: ['transform-classes'],
useBuiltIns: 'entry'
}]
]
}
}
]
if (process.env.NODE_ENV === 'production') {
optimization.minimizer = [
new TerserPlugin({
terserOptions: {
keep_fnames: true,
keep_classnames: true,
mangle: false
},
parallel: true
})
]
plugins.push(
new CompressionPlugin({
algorithm: 'gzip'
})
)
}
module.exports = {
target: 'web',
entry,
output,
devtool: process.env.NODE_ENV === 'production' ? 'source-map' : 'eval',
node: {
__dirname: true,
fs: 'empty'
},
plugins,
optimization,
stats: 'minimal',
module: {
rules
}
}