files. On any change, these tools perform a full rebuild. Concatenation causes dead code. e.g.: pulling Lodash and momentJS into a project - Multiple IIFEs (Immediately Invoked Function Expressions) are slow. Bundlers early on were creating lots of IIFEs. Task runners can’t lazy load.
./bundle.js If Webpack is installed locally: > ./node_modules/.bin/webpack index.js ./bundle.js Best practice: define a NPM script and use config file.
automatically transpiled. Starting with Babel 6, everything is opt-in. • Available transforms: react, es2015, ecmascript stages. Add these in .babelrc if needed. > touch .babelrc { "presets": ["es2015", "stage-1"] }
node-sass. We load CSS into the document’s head w/ style-loader, css-loader. We postprocess the properties with desired vendor prefixes w/ autoprefixer-loader We import the output styles into the file via a link tag instead of inlining w/ extract-text-webpack-plugin.
built-in feature of Webpack. In order to enable it, we add a --watch. package.json "scripts": { "start": "webpack-dev-server", "build:dev": "webpack --watch", "build:prod": "webpack", "clean": "rm -rf build" }, Thus: > npm run build:dev > npm start Note! Don’t forget to: - require the master.scss file in index.js for parsing - include the bundles in your index.html file
allows webpack to reload only chunks of JS code, instead of the whole code base. It can be used with Redux or specific framework loaders for HML. e.g.: react-hot-loader, vue-hot-loader
for images? A: Performance Q: How is it better performing? A: The images are encrypted into base64 and injected into the DOM tree. In other words less HTTP requests. Q: Is there a downside? A: Yes, the image source is assigned via JS. You will manage the images from outside HTML and crawlers will not be able to reach it without prerendering.
preinstalled Webpack plugin. Possible configurations: - Detect repeating dependencies in all entries and split into commons.bundle.js + unique bundles - Manually define dependencies for a vendor.bundle.js which should be included on every page.
a built-in feature. Source maps establish the connection between bundles and the original files. They have a performance drawback. It is best practice to disable them in production. webpack.config.js module.exports = { ... devtool: 'source-map', ... }
[name] before for passing the same filename from dev files to bundles. We can also use [chunkhash] and [contenthash] to add a hash within the filenames.