-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
executable file
·82 lines (73 loc) · 1.76 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
const webpack = require('webpack');
const path = require('path');
const {
paths,
outputFiles,
rules,
plugins,
resolve,
stats,
IS_PRODUCTION,
IS_DEVELOPMENT,
} = require('./webpack/config');
const devServer = require('./webpack/dev-server').devServer;
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Default client app entry file
const entry = [
path.join(paths.javascript, 'client.js'),
];
plugins.push(
// Creates vendor chunk from modules coming from node_modules folder
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: outputFiles.vendor,
minChunks(module) {
const context = module.context;
return context && context.indexOf('node_modules') >= 0;
},
}),
// Builds index.html from template
new HtmlWebpackPlugin({
template: path.join(paths.source, 'index.html'),
path: paths.build,
filename: 'index.html',
minify: {
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
removeComments: true,
useShortDoctype: true,
},
})
);
if (IS_DEVELOPMENT) {
// Development plugins
plugins.push(
// Enables HMR
new webpack.HotModuleReplacementPlugin(),
// Don't emmit build when there was an error while compiling
// No assets are emitted that include errors
new webpack.NoEmitOnErrorsPlugin()
);
// For IE babel-polyfill has to be loaded before react-hot-loader
entry.unshift('babel-polyfill');
}
// Webpack config
module.exports = {
devtool: IS_PRODUCTION ? false : 'cheap-eval-source-map',
context: paths.javascript,
watch: !IS_PRODUCTION,
entry,
output: {
path: paths.build,
publicPath: '/',
filename: outputFiles.client,
},
module: {
rules,
},
plugins,
resolve,
stats,
devServer,
};