Kerry converted her company's build system and test suite from Require.js / Grunt to Webpack. This talk outlines some of the real benefits they gained, and struggles hit along the way
module formats (AMD, CommonJS etc) Configuration files are easy to understand Hot Module Replacement Code Splitting Loaders Easy to make the leap from development to production with the likes of plugins
module.exports = { // The base directory for resolving the entry option context: __dirname + "/app/coffeescript", // The entry point for the bundle entry: "./bootstrap.coffee", // Various output options, to give us a single bundle.js file with everything output: { path: __dirname + '/app/webpack', filename: "bundle.js", publicPath: '/app/webpack/', pathinfo: true Some lines left out for brevity
or “load” them" module: { loaders: [ { test: /\.csx.coffee$/, loaders: ['coffee', 'cjsx']}, { test: /^(?=.*coffee)(?!.*csx).*/, loader: 'coffee' }, { test: /\.html$/, loader: "mustache"}, { test: /\.json$/, loader: "json"} ] } Loaders can be resolved from anywhere, node_modules is conveniently used by default They can be chained, making them very powerful
By default a <style></style> Can be utilised in production by making use of the ExtractTextPlugin { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader" plugins: [new ExtractTextPlugin("app/assets/css/site.css")]
use of webpack-dev-server. output: { path: __dirname + '/app/webpack', filename: "bundle.js", publicPath: "http://localhost:8080/app/webpack" } And an extra loader to process CJSX files { test: /\.csx.coffee$/, loaders: ['react-hot', 'coffee', 'cjsx']} Run with: webpack-dev-server --inline --hot
many of the common production requirements plugins: [ new webpack.optimize.UglifyJsPlugin({ mangle: { except: ['$super', '$', 'exports'] }, output: { comments: false } }), new webpack.optimize.DedupePlugin(), new webpack.optimize.OccurenceOrderPlugin(false) ]
were using Lodash like this: _(somethingToWorkOn) , but we weren't calling .value() in all cases React.js components weren't rendering where a lowercase letter had been used