Playbook
Search…
Webpacker
Use Webpack to manage app-like Javascript modules in Rails

Overview

Webpacker makes it easy to use the Javascript pre-processor and bundler to manage application-like Javascript in Rails. It coexists with the asset pipeline, as the primary purpose for webpack is app-like Javascript, not images, CSS, or even Javascript Sprinkles (that all continues to live in app/assets).
However, it is possible to use Webpacker for CSS, images and fonts assets as well, in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based Javascript frameworks.

Installation

1
bundle install
2
bundle exec rails webpacker:install
3
​
4
yarn upgrade
5
yarn install
Copied!

Usage

Once installed, you can start writing modern ES6 Javascript apps right away:
1
app/frontend:
2
β”œβ”€β”€ packs:
3
β”‚ # only webpack entry files here
4
β”‚ └── application.js
5
β”‚ └── application.scss
6
└── components:
7
β”‚ └── header.vue
8
└── icons:
9
β”‚ └── euro.svg
10
└── stylesheets:
11
β”‚ └── application.scss
12
β”‚ └── tailwind.css
13
└── images:
14
└── placeholeder.jpg
Copied!

Hot reloading

1
./bin/webpack-dev-server
Copied!