/
webpack.config.js
49 lines (46 loc) · 1.24 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
const path = require('path')
const webpack = require('webpack')
const here = p => path.join(__dirname, p)
module.exports = (env = process.env.NODE_ENV || 'development') => {
const prod = env === 'production'
const serve = JSON.parse(process.env.WEBPACK_SERVE || 'false')
return removeEmpty({
context: here('src'),
entry: './index.js',
output: {
path: here('dist'),
pathinfo: true,
filename: 'bundle.js',
publicPath: '/'
},
mode: prod ? 'production' : 'development',
devtool: prod ? 'source-map' : 'cheap-module-source-map',
plugins: removeEmpty([
prod ? null : new webpack.HotModuleReplacementPlugin()
]),
serve: serve
? {
content: here('./public'),
clipboard: false,
// logLevel: 'warn', // defaults to 'info' and it's noisy
hot: {
hot: true
// logLevel: 'warn', // defaults to 'info' and it's noisy
// reload: true,
}
}
: null
})
}
function removeEmpty(input) {
if (Array.isArray(input)) {
return input.filter(item => item != null)
} else {
return Object.entries(input).reduce((a, [k, v]) => {
if (v != null) {
a[k] = v
}
return a
}, {})
}
}