Upgrade to Webpack 4

This commit is contained in:
Tim Schaub
2018-01-25 09:47:01 -07:00
committed by ahocevar
parent 79a5bd6538
commit 48cbca1f6e
4 changed files with 23 additions and 69 deletions

View File

@@ -1,10 +1,7 @@
const MinifyPlugin = require('babel-minify-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ExampleBuilder = require('./example-builder');
const fs = require('fs');
const merge = require('webpack-merge');
const path = require('path');
const webpack = require('webpack');
const src = path.join(__dirname, '..');
@@ -17,15 +14,17 @@ examples.forEach(example => {
entry[example] = `./${example}.js`;
});
const main = {
module.exports = {
context: src,
target: 'web',
entry: entry,
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
optimization: {
splitChunks: {
name: 'common', // TODO: figure out why this isn't working
minChunks: 2
}),
}
},
plugins: [
new ExampleBuilder({
templates: path.join(__dirname, '..', 'templates'),
common: 'common'
@@ -38,45 +37,10 @@ const main = {
{from: 'index.html', to: 'index.html'}
])
],
// TODO: figure out why this hangs
// devtool: 'source-map',
output: {
filename: '[name].js',
path: path.join(__dirname, '..', '..', 'build', 'examples')
}
};
// configuration specific to the dev environment
const dev = {
devtool: 'source-map',
plugins: [
new webpack.EnvironmentPlugin(
Object.assign({NODE_ENV: 'development'}, process.env)
)
]
};
// configuration specific to the prod environment
const prod = {
plugins: [
new webpack.EnvironmentPlugin(
Object.assign({NODE_ENV: 'production'}, process.env)
),
new MinifyPlugin()
]
};
module.exports = env => {
let config;
switch (env) {
case 'prod': {
config = merge(main, prod);
break;
}
default: {
config = merge(main, dev);
}
}
return config;
};