Jass::Rollup – Rollup for Sprockets and the Rails asset pipeline
Jass::Rollup
integrates the Rollup JS bundler with Sprockets and the Rails asset pipeline.
💡 Motivation
JavaScript build pipelines tend to be a complicated mess consisting of dev servers,
an infinite number of npm
dependencies and other "opinionated" conventions (and lack thereof).
The Jass
gem series provide a straightforward way of integrating modern JS tooling
with the existing Rails asset pipeline, while adhering to established workflows
for asset processing in Rails applications.
📦 Installation
Gemfile
gem 'jass-rollup'
JS dependencies
Add rollup
to your JS dependencies:
$ yarn add rollup @rollup/plugin-commonjs @rollup/plugin-node-resolve
Node.js
Jass::Rollup
depends on Nodo, which requires a working Node.js installation.
⚡️ Usage
Jass::Rollup
provides two new directives to use in your JS assets, as well as
a new Sprockets file extension for rollup bundle config files.
rollup
The rollup
directive will invoke Rollup
with the given entry point
relative to your Rails.root
.
To bundle an entry point as ES module:
//= rollup app/javascript/entry.js
To bundle a npm
module as ES module:
//= rollup vendor/node_modules/rxjs/dist/esm5/index.js
rollup_esm
The require_esm
directive will bundle a npm
module referenced by its
name as ES module:
//= rollup_esm currency.js
Bundling with custom rollup configurations
If your Rollup bundle requires extra configuration options, e.g. plugins, the file
extension .rollup
can be used:
// assets/javascript/main.js.rollup
export default {
input: 'app/javascript/entry.js',
output: {
format: 'es'
}
};
This asset will be bundled to main.js
.
💎 Other Jass gems for the asset pipeline
Jass::Esbuild – esbuild support for Sprockets
Jass::Vue::SFC – Vue Single File Component support for Sprockets
Jass::React::JSX – React JSX support for Sprockets