Ruby on Rails 7, now in its alpha stage, introduces a significant overhaul in how JavaScript is handled within the framework. After five years of reliance on the Webpacker tool for bundling JavaScript, Rails 7 shifts to a new approach that eliminates the need for Node.js, offering a more streamlined and modern way to handle JavaScript dependencies. This change comes as browser support for ECMAScript 6 and JavaScript modules improves, making it easier for developers to import JavaScript modules directly without the need for complex tooling.
The update also brings the Import Maps for Rails tool into play, allowing developers to manage JavaScript modules directly in the browser without having to worry about the Node.js environment. This shift offers the advantage of a simplified development experience by removing the reliance on node_modules and bundling configurations. It allows Rails developers to focus more on application logic and less on the complexities of JavaScript build systems.
Along with this change, Rails 7 replaces the older TurboLinks and Rails UJS with the Stimulus JS framework and Turbo tool. This transition reduces the need for writing custom JavaScript, providing developers with a comprehensive front-end setup out of the box. With these tools, developers can build highly interactive, client-side functionality without the overhead of managing complex JavaScript dependencies, making Rails 7 a more cohesive and user-friendly platform for full-stack development.
Additionally, Rails 7 has improved integration with JavaScript and CSS bundlers, such as Esbuild, Rollup.js, and Webpack. This enhancement is facilitated by new companion gems that integrate with Rails’ updated bundling system. Whether you’re starting a new application or modifying an existing one that uses import maps, these new tools make it easier to incorporate modern bundling technologies into your Rails projects, providing the flexibility to choose the best tool for your needs.