Rails applications with Rollup bundling
The rails new --javascript=rollup
command creates Rails applications optimized for clean, efficient JavaScript bundling through ES modules. Rollup excels in producing optimized bundles for libraries, ensuring that only the necessary code is included, which can lead to smaller file sizes and improved performance.
Why Rollup excels at optimization
Superior tree-shaking capabilities represent Rollup's primary strength. Rollup supports ES modules natively and provides tree-shaking capabilities, allowing developers to reduce bundle size by eliminating unused code.
Rollup is particularly well-suited for building libraries and applications where performance and bundle size are critical.
What the Rails generator configures
The generator adds jsbundling-rails to your Gemfile, creates rollup.config.js with optimization-focused settings, and configures ./bin/dev
for Rails and Rollup coordination. Node.js and Yarn must be installed when using Rollup.
Performance characteristics
Rollup is generally slower than esbuild but offers efficient bundling through its tree-shaking capabilities, which can optimize the output by removing unused code. Rollup takes the lead in performance benchmarks, designed with performance in mind and excelling at generating optimized bundles quickly.
When to choose Rollup
Choose Rollup if your project focuses on library development or requires tree-shaking capabilities to eliminate dead code. Rollup excels in building libraries and applications that utilize ES modules, providing optimized bundles with tree-shaking to reduce size.