Use Webpack to manage app-like Javascript modules in Rails


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.


bundle install
bundle exec rails webpacker:install
yarn upgrade
yarn install


Once installed, you can start writing modern ES6 Javascript apps right away:
β”œβ”€β”€ packs:
β”‚ # only webpack entry files here
β”‚ └── application.js
β”‚ └── application.scss
└── components:
β”‚ └── header.vue
└── icons:
β”‚ └── euro.svg
└── stylesheets:
β”‚ └── application.scss
β”‚ └── tailwind.css
└── images:
└── placeholeder.jpg

Hot reloading