-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
87 lines (79 loc) · 2 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
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const WebpackHMRPlugin = require('nodeblues/webpack').WebpackHMRPlugin;
const BUILD_DIR = path.resolve(__dirname, './build/web');
const SRC_DIR = path.resolve(__dirname, './web/src');
const ENTRY_FILE = SRC_DIR + '/index.js';
const isProduction = process.argv.includes('-p');
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': isProduction ? '"production"' : '"development"'
}
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new HtmlWebpackPlugin({
title: 'Counter',
template: './web/index.template.html',
filename: 'index.html',
inject: 'footer',
minify: { collapseWhitespace: true }
})
];
const loaders = [
{
test: /.jsx?/,
include: [SRC_DIR, path.resolve(__dirname, './shared/src')],
loader: 'babel-loader',
options: {
presets: ['env', 'react'],
babelrc: false
}
}
];
// Add production or dev specific plugins and loaders
if (isProduction) {
plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundleAnalyzer.html',
defaultSizes: 'parsed'
}));
} else {
loaders.push({
test: ENTRY_FILE,
loader: 'nodeblues/hmr-loader',
query: {
host: 'localhost',
port: 1338
}
});
plugins.push(new WebpackHMRPlugin('localhost', 1338));
}
const config = {
resolve: {
alias: {
shared: path.resolve(__dirname, 'shared/src')
},
extensions: ['.js', '.jsx'],
modules: [path.resolve(__dirname, 'node_modules')]
},
entry: {
app: ENTRY_FILE,
vendor: ['react', 'react-redux', 'redux', 'react-dom']
},
output: {
path: BUILD_DIR,
filename: '[name]-[hash].js'
},
module: {
loaders
},
plugins
};
module.exports = config;