-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
118 lines (114 loc) · 2.7 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
110
111
112
113
114
115
116
117
118
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
const path = require('path');
const baseConfig = function() {
return {
entry: path.join(__dirname, 'src', 'index.jsx'),
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, 'src'),
loader: 'babel-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
},
output: {
path: path.join(__dirname, 'public'),
publicPath: '/',
filename: 'bundle.[chunkhash].js'
}
}
};
const prodConfig = function(env) {
return webpackMerge(baseConfig(), {
stats: {
warnings: false
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
},
API_HOST: JSON.stringify(process.env.API_HOST)
}),
new webpack.optimize.UglifyJsPlugin({
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
screw_ie8: true
},
comments: false
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './public/index.template.html'
}),
new SWPrecacheWebpackPlugin({
cacheId: 'dude-expenses',
filename: 'sw.js',
minify: true,
staticFileGlobs: [
'index.html',
'bundle*.js',
'icons/*.png'
],
mergeStaticsConfig: true
})
]
});
};
const devConfig = function(env) {
return webpackMerge(baseConfig(), {
devtool: 'eval',
devServer: {
contentBase: './public',
hot: true,
historyApiFallback: true
},
output: {
path: path.join(__dirname, 'public'),
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
API_HOST: JSON.stringify(process.env.API_HOST || 'http://www.dude-expenses.dev')
}),
new HtmlWebpackPlugin({
template: './public/index.template.html',
inject: 'body'
}),
new SWPrecacheWebpackPlugin({
cacheId: 'dude-expenses',
filename: 'sw.js',
minify: true,
staticFileGlobs: [
'index.html',
'bundle*.js',
'icons/*.png'
]
})
]
});
};
module.exports = function(env) {
if (env === 'production') {
return prodConfig();
} else {
return devConfig();
}
};