-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
76 lines (68 loc) · 2.07 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
const path = require('path');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
var webpack = require('webpack');
const isProd = process.env.NODE_ENV === 'production'
|| process.argv.slice(-1)[0] == '-p'
|| process.argv.some(arg => arg.indexOf('webpack-dev-server') >= 0);
const webpackReport = process.env.WEBPACK_REPORT ==='true';
console.log(`Environment: ${process.env.NODE_ENV}`);
console.log(`Production Environment: ${isProd}`);
console.log(`Generated report: ${webpackReport}`);
function getPlugins() {
const plugins = [];
// pass env to webpack
plugins.push(new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}
}));
if(isProd) {
plugins.push(new webpack.optimize.UglifyJsPlugin({
uglifyOptions: {
mangle: false
}
}));
}
if(webpackReport) {
plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static'
}))
}
return plugins.concat([
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new CopyWebpackPlugin([{
from: 'src/public',
to: '../public'
},{
from: 'src/server',
to: '../server'
}])
]);
}
module.exports = {
watch: true,
entry: {
vendor: ['react', 'react-dom', 'axios'],
index: './src/react/index.jsx',
},
output: {
path: path.join(__dirname, 'dist/public'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js'
},
module: {
rules: [
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
{ test: /\.js.?$/, loader: 'babel-loader', exclude: /node_modules/ },
{ test: /\.json$/, loader: 'json-loader' }
],
},
plugins: getPlugins()
}