-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
103 lines (92 loc) · 1.87 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
94
95
96
97
98
99
100
101
102
103
/* eslint-disable */
var webpack = require('webpack');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var path = require('path');
var env = process.env.NODE_ENV;
var libraryName = '[name]';
var plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
})
];
var outputFile;
if (env === 'production') {
plugins.push(new UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: true
},
}));
plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true
}));
outputFile = libraryName + '.min.js';
} else {
outputFile = libraryName + '.js';
}
var config = {
entry: {
'thin-react-router': [
path.join(__dirname, '/src/index.js')
]
},
devtool: 'source-map',
output: {
path: path.join(__dirname, 'dist'),
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
modules: [
path.join(__dirname, "src"),
"node_modules"
],
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
}
]
},
externals: [
{
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
},
{
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
},
},
{
'prop-types': {
root: 'PropTypes',
commonjs2: 'prop-types',
commonjs: 'prop-types',
amd: 'prop-types'
}
}
],
plugins: plugins
};
module.exports = function (env) {
if (env) {
if (env.analyze) {
config.plugins.push(new BundleAnalyzerPlugin());
}
}
return config;
};