-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
72 lines (69 loc) · 2.43 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
var webpack = require('webpack');
var CleanPlugin = require('clean-webpack-plugin');
var isProductionMode = process.argv.indexOf('-production') != -1;
var buildDistPath = 'builds';
module.exports = {
devtool: isProductionMode ? undefined : 'source-map',
entry: './src',
output: {
path: buildDistPath,
filename: 'bundle.js',
chunkFilename: '[name].js', //allow to name split chunks
publicPath: buildDistPath + '/'
},
module: {
preLoaders: [
{
test: /\.js/,
loader: 'eslint',
}
],
loaders: [
{
test: /\.js/,
exclude: /(node_modules|bower_components)/, //avoid that babel will treaverse files third-party code //TODO is it needed? webpack entry is ./src'
loader: 'babel',
query: {presets: ['es2015']}
},
{
test: /\.html/,
loader: 'html',
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.(png|gif|jpe?g|svg)$/i,
loader: 'url',
query: {limit: 10000} //if the asset is smaller than 10kb inline it, instead of giving the url
}
]
},
plugins:
isProductionMode
?
[
// Cleanup the builds/ folder before compiling
new CleanPlugin(buildDistPath),
// prevents creating chunks that would be too small to be worth loading separately
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 51200, // ~50kb
}),
//extract common chunks dependency into a shared js
new webpack.optimize.CommonsChunkPlugin({
name: 'main', // Move dependencies to our main file
children: true, // Look for common dependencies in all children,
minChunks: 2, // How many times a dependency must come up before being extracted
}),
//minify code
new webpack.optimize.UglifyJsPlugin({
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
},
})
]
:
[]
};