testcafe-workshop/webpack.config.babel.js
Børge Antonsen a4bc8585b7 Merge branch 'FEM/02.2-add-webpack'
# Conflicts:
#	karma.conf.js
#	package.json
#	src/app.js
#	src/bootstrap.js
#	src/controller.test.js
#	src/index.html
#	webpack.config.babel.js
2018-10-15 22:26:58 +02:00

57 lines
1.8 KiB
JavaScript

/* eslint no-console:"off" */
const {resolve} = require('path')
const webpack = require('webpack')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const webpackValidator = require('webpack-validator')
const {getIfUtils, removeEmpty} = require('webpack-config-utils')
const OfflinePlugin = require('offline-plugin')
module.exports = env => {
const {ifProd, ifNotProd} = getIfUtils(env)
const config = webpackValidator({
context: resolve('src'),
entry: {
app: './bootstrap.js',
vendor: ['todomvc-app-css/index.css'],
},
output: {
filename: ifProd('bundle.[name].[chunkhash].js', 'bundle.[name].js'),
path: resolve('dist'),
pathinfo: ifNotProd(),
},
devtool: ifProd('source-map-loader', 'eval'),
module: {
loaders: [
{test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/},
{test: /\.css$/, loaders: ['style-loader', 'css-loader']},
],
},
plugins: removeEmpty([
new ProgressBarPlugin(),
new ExtractTextPlugin(ifProd('styles.[name].[chunkhash].css', 'styles.[name].css')),
ifProd(new InlineManifestWebpackPlugin()),
ifProd(new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
})),
new HtmlWebpackPlugin({
template: './index.html',
inject: 'head',
}),
new OfflinePlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: ifProd('"production"', '"development"')
}
}),
]),
})
if (env.debug) {
console.log(config)
debugger // eslint-disable-line
}
return config
}