Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Webpack 2 Config
var path = require('path');
var merge = require('webpack-merge');
var webpack = require('webpack');
var ProgressPlugin = require('webpack/lib/ProgressPlugin');
var CleanPlugin = require('clean-webpack-plugin');
var webpackUtils = require('./webpackUtils'); // helper file for common tasks
var common;
var config;
common = {
entry: {
'app': path.join(__dirname, './app.js'),
'vendor': [
path.join(__dirname, './react-bundle.js')
]
},
output: {
filename: '[name].js',
path: 'build',
publicPath: 'build',
chunkFilename: '[chunkhash].[name].js'
},
module: {
loaders: [{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.json$/,
loader: 'json-loader'
}, {
test: /\.scss$/,
loaders: ['style', 'css', 'sass']
}]
},
externals: {
'd3': 'd3',
'fbjs': 'fbjs',
'intl': 'Intl',
'moment': 'moment',
'moment/min/locales': 'momentLocales',
'moment-timezone': 'moment'
},
plugins: [
new ProgressPlugin(),
new CleanPlugin(['core/'], {
verbose: false,
exclude: [
'react-bundle.js',
'app.js'
],
root: 'build'
})
]
};
switch (process.env.NODE_ENV) {
case 'production':
config = merge(
common,
{
output: {
filename: '[name].min.js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity,
filename: 'vendor-bundle.min.js'
})
]
},
webpackUtils.setFreeVariable(
'process.env.NODE_ENV',
'production'
),
webpackUtils.minify()
);
break;
default: // development
config = merge(
common,
{
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity,
filename: 'vendor-bundle.js'
})
],
devtool: 'inline-source-map'
},
webpackUtils.setFreeVariable(
'process.env.NODE_ENV',
'development'
)
);
break;
}
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.