-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (95 loc) · 2.13 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
103
104
105
106
107
108
109
var webpack = require('webpack');
var merge = require('webpack-merge');
var autoprefixer = require('autoprefixer');
var path = require('path');
var TARGET = process.env.npm_lifecycle_event;
process.env.BABEL_ENV = TARGET;
var target = path.resolve(__dirname, 'build/');
console.log('Target: ' + target);
var common = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'app/index.jsx')
],
output: {
path: target,
filename: '[name].js'
},
resolve: {
alias: { '~': path.resolve(__dirname, 'app/') },
extensions: ['', '.js', '.jsx', '.json', '.scss'],
modulesDirectories: ['node_modules']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: [
'react-hot',
'babel?presets[]=react,presets[]=es2015,presets[]=stage-0,presets[]=stage-1,presets[]=stage-2,plugins[]=add-module-exports'
],
include: [
path.resolve(__dirname, 'app/'),
],
},
{
test: /\.json$/,
loader: 'json',
},
{
test: /\.scss$/,
loader: 'style!css!postcss!sass',
include: path.resolve(__dirname, 'app/')
},
{
test: /\.css$/,
loader: 'style!css!postcss'
}
]
},
sassLoader: {
includePaths: [path.resolve(__dirname, 'node_modules/')]
},
postcss: function() {
return {
defaults: [autoprefixer],
cleaner: [autoprefixer({ browsers: [
'Chrome >= 35',
'Firefox >= 31',
'Edge >= 12',
'Explorer >= 9',
'iOS >= 8',
'Safari >= 8',
'Android 2.3',
'Android >= 4',
'Opera >= 12'
]})]
}
}
};
if (TARGET === 'build') {
module.exports = merge(common, {
plugins: [
new webpack.DefinePlugin({
'process.env': { 'NODE_ENV': JSON.stringify('production') }
}),
new webpack.optimize.UglifyJsPlugin()
]
});
}
if (TARGET === 'start') {
module.exports = merge(common, {
devtool: 'eval-source-map',
devServer: {
// --hot --inline --progress in package.json script (npm run start)
path: target,
filename: '[name].js',
publicPath: 'http://localhost:8080/',
recordsPath: target,
contentBase: target,
host: '0.0.0.0',
historyApiFallback: true
}
});
}