-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
executable file
·61 lines (58 loc) · 1.67 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
const { resolve, join } = require('path')
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
module.exports = (env = {}) => {
console.log('env : ', env)
const libraryName = 'taskorama'
const addPlugin = (add, plugin) => (add ? plugin : undefined)
const ifProd = plugin => addPlugin(env.prod, plugin)
const ifDev = plugin => addPlugin(env.dev, plugin)
const removeEmpty = array => array.filter(i => !!i)
const config = {
devtool: env.prod ? 'source-map' : 'eval',
entry: {
main: removeEmpty(['./src/index.js']),
browser: removeEmpty(['./src/browser.js'])
},
context: resolve(__dirname, ''),
output: {
path: env.prod ? join(__dirname, '') : join(__dirname, 'dist'),
filename: '[name].js',
publicPath: '',
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
{ test: /\.json$/, loaders: ['json-loader'], exclude: /node_modules/ }
]
},
plugins: removeEmpty([
ifProd(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
),
ifProd(
new webpack.optimize.UglifyJsPlugin({
mangle: false,
comments: false,
compress: {
screw_ie8: true,
warnings: false,
drop_console: true
}
})
),
new CompressionPlugin()
]),
resolve: {
extensions: ['.js', '.json']
}
}
if (env.devServer) config.entry['dev'] = removeEmpty(['./serve/dev.js'])
return config
}