-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
102 lines (94 loc) · 2.49 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
var path = require('path');
var webpack = require('webpack');
var HtmlWebPackPlugin = require('html-webpack-plugin');
var merge = require('webpack-merge');
var pkg = require('./package.json');
var Clean = require('clean-webpack-plugin');
var autoprefixer = require('autoprefixer');
var TARGET = process.env.npm_lifecycle_event;
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');
process.env.BABEL_ENV = TARGET;
var common = {
entry: APP_PATH,
output: {
path: BUILD_PATH,
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['babel'],
include: APP_PATH
},
{
test: /\.css$/,
loaders: ['style', 'css', 'postcss'],
include: APP_PATH
}
]
},
postcss: function () {
return [autoprefixer];
},
plugins: [
new HtmlWebPackPlugin(
{
title: 'Socket.io debugger',
template: 'index-template.html',
inject: 'body',
favicon: 'favicon.png'
}
)
]
};
if(TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: 'source-map',
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});
}
if(TARGET === 'build') {
module.exports = merge(common, {
devtool: 'source-map',
entry: {
app: APP_PATH,
vendor: Object.keys(pkg.dependencies)
},
output: {
path: BUILD_PATH,
filename: '[name].[chunkhash].js?'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.DefinePlugin({
'process.env': {
// This affects react lib size
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.CommonsChunkPlugin(
'vendor',
'[name].[chunkhash].js'
),
new Clean(['build'])
]
});
}