-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
74 lines (65 loc) · 1.63 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
var isDeploy = isArgs('--deploy');
var path = require('path');
var webpack = require('webpack');
var commonPlagins = [
new webpack.DefinePlugin({
'ENV_isDeploy': JSON.stringify(isDeploy)
})
];
var devPlagins = [
new webpack.HotModuleReplacementPlugin(),
];
var deployPlagins = [
new webpack.optimize.UglifyJsPlugin({ compress: {warnings: false} })
];
module.exports = {
entry: setEntrySources([
path.join(__dirname, '/src/main.js')
]),
output: {
path: path.join(__dirname, '/build'),
filename: 'bundle.js',
publicPath: '/build/'
},
plugins: isDeploy ? commonPlagins.concat(deployPlagins) : commonPlagins.concat(devPlagins),
module: {
loaders: [{
test: /\.js?$/,
loader: 'babel',
include: path.join(__dirname, "/src"),
query: {
presets: ['react', 'es2015']
}
}, {
test: /\.styl?$/,
loader: 'style!css!stylus',
}]
},
//devtool: isDeploy ? null : 'eval',
};
function isArgs(str) {
return (process.argv.indexOf(str) > -1);
}
function setEntrySources(sources) {
if(!isDeploy) {
switch(typeof sources) {
case('object'):
var tempObj = {};
for(var key in sources) {
tempObj[key] = setEntrySources(sources[key]);
}
return tempObj;
case('array'):
var tempArr = ['webpack-dev-server/client'];
tempArr.concat(sources);
return tempArr;
case('string'):
var tempArrStr = ['webpack-dev-server/client'];
tempArrStr.push(sources);
return tempArrStr;
default:
return sources;
}
}
return sources;
}