Introduction to Webpacker

Get introduced to Webpacker in this lesson.

We'll cover the following

As Rails 6 developers, our primary interaction with webpack is going to be through the Webpacker tool provided by Rails. In this chapter, I’ll talk about using Webpacker in development, and also how to customize it when you want additional features.

The Webpacker gem is a default part of a new Rails 6 installation, which means Webpacker goes in the Gemfile, and by default, the webpack:install task is run when the app is created. You can skip Webpacker entirely with rails new . --skip-webpack-install, or you can install one of the existing frameworks with something like rails new . --webpack=stimulus.

After the app is created, you can add Webpacker to an existing app with the rake task rails webpacker:install, which has options like rails webpacker:install:stimulus for each framework or add-on Webpacker supports.

Webpacker basics

Webpacker is a wrapper around webpack designed to make webpack easier to manage within a Rails application.

The main thing Webpacker does is generate a webpack configuration using a set of inputs that is hopefully simpler to deal with than a full webpack configuration. The file, config/webpacker.yml file has a lot of webpack default values, and specific environment overrides are in the config/webpack directory.

Get hands-on with 1400+ tech skills courses.