Created
August 12, 2016 15:39
-
-
Save DevinClark/3c34c7fa8856696f155134143defb3d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var glob_entries = require('webpack-glob-entries'); | |
var webpack = require('webpack'); | |
var validate = require('webpack-validator'); | |
var env = process.env.NODE_ENV || 'development'; | |
var entries = glob_entries('./src/js/component/page/*.js'); | |
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); | |
var webpackConfig = { | |
// create multiple entry points from all of the page level components | |
entry: entries, | |
// write the bundled files using same filename | |
output: { | |
path: __dirname + '/dist/js', | |
publicPath: "/js/", | |
filename: '[name].js' | |
}, | |
module: { | |
loaders: [ | |
// handle requiring JSON files | |
{test: /\.json$/, loader: 'json-loader'}, | |
// run the JS through babel to compile JSX (see .babelrc for more details) | |
{test: /\.js$/, loader: 'babel-loader', exclude: 'node_modules/'} | |
] | |
}, | |
plugins: [ | |
// add process.env.NODE_ENV | |
new webpack.EnvironmentPlugin([ | |
"NODE_ENV" | |
]), | |
new LodashModuleReplacementPlugin({ | |
collections: true, | |
shorthands: true | |
}) | |
] | |
}; | |
if (env === 'development') { | |
webpackConfig.watch = true; | |
webpackConfig.watchOptions = { | |
aggregateTimeout: 300, | |
poll: 1000 | |
}; | |
webpackConfig.progress = true; | |
webpackConfig.devtool = 'cheap-source-map'; | |
webpackConfig.devServer = { | |
contentBase: "." | |
}; | |
} | |
if (env === 'staging' || env === 'production') { | |
// Compress the js | |
webpackConfig.plugins.unshift(new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false | |
}, | |
output: { | |
comments: false | |
} | |
})); | |
// build a common bundle (common.js) out of any file that is required in 3 different entry points | |
// this will contain things like React, ReactDOM, and probably all of the atom layer components. | |
webpackConfig.plugins.unshift(new webpack.optimize.CommonsChunkPlugin({ | |
name: "common", | |
filename: "common.js", | |
minChunks: 3 | |
})); | |
} | |
module.exports = validate(webpackConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment