Skip to content

Instantly share code, notes, and snippets.

@spencercarnage
Last active December 19, 2016 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spencercarnage/104d40400740a141b7d9a6c07f80edf3 to your computer and use it in GitHub Desktop.
Save spencercarnage/104d40400740a141b7d9a6c07f80edf3 to your computer and use it in GitHub Desktop.
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