app/assets/builds to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to
.gitignore by default).
You develop using this approach by running the bundler in watch mode in a terminal with
app/assets/builds/application.js (and all other entry points configured). You can refer to the build output in your layout using the standard asset pipeline approach with
When you deploy your application to production, the
assets:precompile task to ensure that all your package dependencies from
package.json have been installed via yarn, and then runs
yarn build to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
This also happens in testing where the bundler attaches to the
test:* tasks (like
test:controllers), not "rails test", as that doesn't load
If your testing library of choice does not define a
test:prepare Rake task, ensure that your test suite runs
You can configure your bundler options in the
build script in
package.json or via the installer-generated
rollup.config.js for rollup.js or
webpack.config.json for Webpack (esbuild does not have a default configuration format).
You must already have node and yarn installed on your system. You will also need npx version 7.1.0 or later. Then:
jsbundling-railsto your Gemfile with
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with
rails new myapp -j [esbuild|rollup|webpack].