Top Banner
Webpack Bundle your modules with Jake Peyser November 2nd, 2016
10

Bundle your modules with Webpack

Mar 20, 2017

Download

Engineering

Jake Peyser
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bundle your modules with Webpack

WebpackBundle your modules with

Jake PeyserNovember 2nd, 2016

Page 2: Bundle your modules with Webpack

“The module bundler. That also supports pre-processing, code splitting, request

caching, automatic reloading…”

Page 3: Bundle your modules with Webpack

• Front end development involves many repetitive tasks

• Production SPAs require a lot of code per page

• Scalable web apps require efficient static content delivery

But…why?

Page 4: Bundle your modules with Webpack

Output

index.js

webpack.config.js

• Specify your source code entry point

• Designate your bundled output destination

The Basics

Page 5: Bundle your modules with Webpack

Outputindex.js

message.js

• Webpack will crawl the dependency graph, starting at your entry

• Creates a single JS file for each designated bundle

Module Bundling

Page 6: Bundle your modules with Webpack

webpack.config.js

index.js

App.js

Output

• Transpile source code using loaders (eg. jsx -> js)

• Chain and automate the order in which loaders run

• Common functionality is provided by webpack and others through plugins

Task Running & Plugins

Page 7: Bundle your modules with Webpack

Output

webpack.config.js

• Split your code into main and vendor bundles

• Creates a single JS file for each designated bundle

• Cache code that does not change often to decrease initial page load time

Code Splitting

Page 8: Bundle your modules with Webpack

• Most popular build tool adopted by the React community

• Powerful and very heavy on configuration

• create-react-app provides a boilerplate with nice abstraction

• Most advanced features are not necessary outside of production

Key Points

Page 9: Bundle your modules with Webpack

• Webpack: When to Use and Why • Gulp vs Grunt: Why use task runners and the elegance of plugins • Create React Apps with No Configuration • Utilizing Webpack and Babel to build a React.js App • SurviveJS: Webpack from Apprentice to Master • Webpack Docs • Webpack 2.0 Docs (work in progress) • jakepeyser/webpack-intro

Helpful Resources

Page 10: Bundle your modules with Webpack

• DedupePlugin - Deduplicate equal or similar files in the output • UglifyJSPlugin - Minimize all JavaScript output of chunks • CommonsChunkPlugin - Split code into chunks • OfflinePlugin - Makes your app offline ready by caching all (or some) output assets • DefinePlugin - Create global constants which can be configured at compile time • HotModuleReplacementPlugin - Enables Hot Module Replacement • HtmlWebpackPlugin - Simplifies creation of HTML files to serve your webpack bundles

Useful Plugins