-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
94 lines (85 loc) · 2.14 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
const merge = require('webpack-merge');
const path = require('path');
const webpack = require('webpack');
const precss = require('precss');
const autoprefixer = require('autoprefixer');
const ENV = require('./env');
const PATHS = {
src: path.join(__dirname, 'src'),
build: path.join(__dirname, 'www'),
};
const cssLoaders = [
'style-loader',
'css-loader?url=false',
'postcss-loader',
];
const definePlugin = new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
});
process.env.BABEL_ENV = ENV;
const common = {
entry: PATHS.src,
output: {
path: PATHS.build,
filename: 'bundle.js',
},
resolve: {
alias: {
actions: `${__dirname}/src/actions/`,
components: `${__dirname}/src/components/`,
containers: `${__dirname}/src/containers/`,
reducers: `${__dirname}/src/reducers/`,
stores: `${__dirname}/src/stores/`,
utils: `${__dirname}/src/utils/`,
},
},
postcss() {
return [autoprefixer, precss];
},
module: {
loaders: [
{
test: /\.css$/,
loader: cssLoaders.join('!'),
includes: [PATHS.src, PATHS.node_modules],
},
{
test: /\.jsx?$/,
loader: 'babel?cacheDirectory',
include: PATHS.src,
},
{
include: /\.json$/,
loaders: ['json-loader'],
},
],
},
plugins: [definePlugin],
};
if (ENV === 'development') {
module.exports = merge(common, {
devServer: {
contentBase: PATHS.build,
// Enable history API fallback so HTML5 History API based
// routing works. This is a good default that will come
// in handy in more complicated setups.
historyApiFallback: true,
hot: true,
inline: true,
progress: true,
// Display only errors to reduce the amount of output.
stats: 'errors-only',
// Parse host and port from env so this is easy to customize.
host: process.env.HOST,
port: process.env.PORT,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
});
} else {
// config can be added here for minifying / etc
module.exports = merge(common, {});
}