Using Webpack for Production JavaScript Applications

64 minutes

Webpack is one of the most popular tools for bundling JavaScript applications and libraries, and it's growing more popular every day. It is so loaded with features that it's sometimes difficult to know what's even possible.

In this course, Kent C. Dodds takes you through some of the most valuable features of the Webpack JavaScript module bundler. We'll learn a ton about what it takes to optimize your Webpack configuration and your application to make it as fast as it can possibly be. We'll also go over what it takes to setup and write tests with webpack, Karma, Mocha, and Chai.

This course covers Webpack 2, but should also be relevant for Webpack 1.x.

pro-course-rss-logo

PRO RSS Feed

Intro to the Production Webpack Course

Validate your Webpack config with webpack-validator

P

Tree shaking with Webpack 2

P

Polyfill Promises for Webpack 2

P

Maintain sane file sizes with webpack code splitting

P

Hashing with Webpack for long term caching

P

Grouping vendor files with the Webpack CommonsChunkPlugin

P

Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin

P

Optimize React size and performance with Webpack production plugins

P

Import a non-ES6 module with Webpack

P

Expose modules to dependencies with Webpack

P

Initialize a Webpack Project with Karma for Testing

P

Use Chai assertions for tests in a Karma project

P

Use Karma for Unit Testing with Webpack

P

Add Code Coverage to tests in a Webpack project

P

Ensure all source files are included in test coverage reports with Webpack

P
otherjs tutorial about Intro to the Production Webpack Course

Intro to the Production Webpack Course

2:14 otherjs

There are several lessons that will build on top of this project. It is a fairly standard, small webpack bundled project. In this lesson we’ll explore the project a bit so you’re familiar with how things are set up for future lessons.

otherjs tutorial about Validate your Webpack config with webpack-validator

Validate your Webpack config with webpack-validator

4:06 otherjs PRO

It’s quite common to make a mistake while developing your webpack configuration. A simple typo can cost you hours of development time. With webpack-validator, you can save yourself a ton of time by validating that your webpack configuration is free of common mistakes.

Note: Webpack 2 now has validation baked in.

otherjs tutorial about Tree shaking with Webpack 2

Tree shaking with Webpack 2

3:23 otherjs PRO

The less code you can send to the browser, the better. The concept of tree shaking basically says that if you’re not using some piece of code, then exclude it from the final bundle, even when that piece of code is exported from a module. Because ES6 modules are statically analyzable, Webpack can determine which of your dependencies are used and which are not. In this lesson, see how to take advantage of this awesome feature in Webpack 2.

otherjs tutorial about Polyfill Promises for Webpack 2

Polyfill Promises for Webpack 2

1:59 otherjs PRO

If you're going to use code splitting with Webpack 2, you'll need to make sure the browser has support for the ES6 Promise API. This means that if you are required to support an old browser, you need to provide a polyfill. Polyfilling is relatively trivial to do with Webpack, but because Webpack itself depends on this particular polyfill, you have to come up with another way of doing so. In this lesson, we'll see how we can use the polyfill.io service to automatically polyfill this API (and others) for us.

otherjs tutorial about Maintain sane file sizes with webpack code splitting

Maintain sane file sizes with webpack code splitting

2:38 otherjs PRO

As a Single Page Application grows in size, the size of the payload can become a real problem for performance. In this lesson, learn how to leverage code splitting to easily implement lazy loading for your application to load only the code necessary for a particular feature or functionality.

otherjs tutorial about Hashing with Webpack for long term caching

Hashing with Webpack for long term caching

3:46 otherjs PRO

Leveraging the browser cache is an important part of page load performance. A great way to utilize this cache is by versioning your resources. In this lesson, learn how to use Webpack’s hashing feature so you can take advantage of long term caching of your assets.

otherjs tutorial about Grouping vendor files with the Webpack CommonsChunkPlugin

Grouping vendor files with the Webpack CommonsChunkPlugin

5:36 otherjs PRO

Often, you have dependencies which you rarely change. In these cases, you can leverage the CommonsChunkPlugin to automatically put these modules in a separate bundled file so they can be cached and loaded separately from the rest of your code (leveraging the browser cache much more effectively).

otherjs tutorial about Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin

Chunking common modules from multiple apps with the Webpack CommonsChunkPlugin

4:11 otherjs PRO

If you have a multi-page application (as opposed to a single page app), you’re likely sharing modules between these pages. By chunking these common modules into a single common bundle, you can leverage the browser cache much more powerfully. In this lesson we’ll use webpack’s CommonsChunkPlugin to easily share common modules between apps.

otherjs tutorial about Optimize React size and performance with Webpack production plugins

Optimize React size and performance with Webpack production plugins

5:45 otherjs PRO

You can fine tune several webpack plugins to make your bundle as small as it can be for your specific application. However there are a few things you can do for pretty much every application to make it smaller and run faster. In this lesson we’ll combine several webpack plugins to optimize things for a React application (this is also applicable for non-React applications as well).

otherjs tutorial about Import a non-ES6 module with Webpack

Import a non-ES6 module with Webpack

4:20 otherjs PRO

When you have a dependency that does not export itself properly, you can use the exports-loader to force it to export the pieces of the file that you need.

otherjs tutorial about Expose modules to dependencies with Webpack

Expose modules to dependencies with Webpack

3:20 otherjs PRO

When you have a dependency that has dependencies on global variables (like jQuery or lodash) or assumes that this is bound to window, you can use the imports-loader to provide those dependencies explicitly.

otherjs tutorial about Initialize a Webpack Project with Karma for Testing

Initialize a Webpack Project with Karma for Testing

5:22 otherjs PRO

There are several steps involved with setting up Karma to work on your webpack project. In this first step we'll initialize our karma configuration and setup our package.json scripts.

otherjs tutorial about Use Chai assertions for tests in a Karma project

Use Chai assertions for tests in a Karma project

1:17 otherjs PRO

Chai assertions work great with the Mocha testing framework. In this lesson we'll walk through out to install Chai and karma-chai so you can use the expect assertions in your tests.

otherjs tutorial about Use Karma for Unit Testing with Webpack

Use Karma for Unit Testing with Webpack

4:53 otherjs PRO

When writing tests run by Karma for an application that’s bundled with webpack, it’s easiest to integrate webpack and Karma directly together. In this lesson we’ll see how to utilize the karma-webpack plugin and reuse our existing webpack configuration to preprocess our test files with webpack.

otherjs tutorial about Add Code Coverage to tests in a Webpack project

Add Code Coverage to tests in a Webpack project

6:30 otherjs PRO

How much of your code runs during unit testing is an extremely valuable metric to track. Utilizing code the karma-coverage plugin and babel-plugin-__coverage__ plugin, we can get an accurate measure of how well we’re covering the files that we are testing.

otherjs tutorial about Ensure all source files are included in test coverage reports with Webpack

Ensure all source files are included in test coverage reports with Webpack

4:59 otherjs PRO

If you’re only instrumenting the files in your project that are under test then your code coverage report will be misleading and it will be difficult for you to track or enforce improvements to application coverage over time. In this lesson we’ll learn how to ensure all source files are included in coverage reports and how to enforce a specific threshold so you can work toward improving application code coverage.

Presented by:

Kent C. Dodds

a JavaScript developer who likes open source and teaching.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?