/* eslint-env node */
const webpack = require('webpack');
const resolve = require('path').resolve;
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = env => {
const addPlugin = (add, plugin) => add ? plugin : undefined;
const ifProd = plugin => addPlugin(env.prod, plugin);
const removeEmpty = array => array.filter(i => !!i);
return {
devServer: {
historyApiFallback: true
},
entry: './app.js',
output: {
filename: 'bundle.[chunkhash].js',
path: resolve(__dirname, 'dist'),
pathinfo: !env.prod,
},
context: resolve(__dirname, 'src'),
devtool: env.prod ? 'source-map' : 'eval',
bail: env.prod,
module: {
loaders: [
{ test: /\.js$/, loader: 'babel!eslint', exclude: /node_modules/ },
{ test: /\.css$/, loader: 'style!css', exclude: /node_modules/ }
]
},
plugins: removeEmpty([
ifProd(new webpack.optimize.DedupePlugin()),
ifProd(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})),
ifProd(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})),
ifProd(new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true, //eslint-disable-line
warnings: false
}
})),
new HtmlWebpackPlugin({ template: '../index.html'})
])
}
};