-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
81 lines (70 loc) · 2.14 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
const path = require('path')
const webpack = require('webpack')
const MinifyPlugin = require('babel-minify-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isProd = process.env.NODE_ENV === 'production'
const getPlugins = (envName) => {
const plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
if (isProd) {
plugins.push(
new MinifyPlugin()
)
if (envName === 'browser') {
plugins.push(
new BundleAnalyzerPlugin({ analyzerPort: 9898 })
)
}
}
return plugins
}
const baseFileName = 'stelace'
const getBaseBundleConfig = (envName) => {
const isNode = envName === 'node'
return {
mode: isProd ? 'production' : 'development',
context: path.join(__dirname, 'lib'),
entry: [`./${baseFileName}.js`],
target: isNode ? 'node' : 'web', // 'web' is webpack default
output: {
path: path.join(__dirname, 'dist'),
libraryTarget: isNode ? 'commonjs2' : 'umd',
library: 'stelace'
},
module: {
rules: [{
test: /\.js?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { envName }
}
}]
},
devtool: isProd ? false : 'source-map',
plugins: getPlugins(envName),
node: false, // remove this property for node
// https://webpack.js.org/configuration/stats/
stats: process.env.DEBUG_BUILD === 'true' ? 'verbose' : true
}
}
// Latest browsers
const evergreenBundle = getBaseBundleConfig('evergreen')
evergreenBundle.output.filename = `${baseFileName}.evergreen${isProd ? '.min' : ''}.js`
// Supports legacy browsers like IE 11
const browserBundle = getBaseBundleConfig('browser')
browserBundle.output.filename = `${baseFileName}.browser${isProd ? '.min' : ''}.js`
// Node
const nodeBundle = getBaseBundleConfig('node')
nodeBundle.output.filename = `${baseFileName}.node${isProd ? '.min' : ''}.js`
nodeBundle.target = 'node'
delete nodeBundle.node
module.exports = [
evergreenBundle,
browserBundle,
nodeBundle
]