Rails Glossary > Generate a Rails app with rollup and no importmap

Generate a Rails app with rollup and no importmap

Creates a new Rails application configured with Rollup, a module bundler focused on ES modules and tree-shaking that produces optimized, smaller bundles ideal for libraries and performance-critical applications.

Rails applications with Rollup bundling

How do you create a Rails app with Rollup? Use rails new myapp --javascript=rollup to generate a new Rails application with Rollup configured as the JavaScript bundler, providing superior tree-shaking capabilities and ES module optimization for minimal bundle sizes.

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.

Try Avo for free