
Modern Asset Pipeline & Frontend
Importmap-rails (Rails 7+), jsbundling/cssbundling, Hotwire (Turbo + Stimulus), Sprockets (legacy)
1What is the default asset management system in Rails 7+?
What is the default asset management system in Rails 7+?
답변
Importmap-rails is the default system in Rails 7+ for managing JavaScript files. It allows using native ES modules directly in the browser without a bundling step, by mapping package names to CDN URLs or local files. This significantly simplifies frontend configuration while eliminating the Node.js dependency.
2How to add an external JavaScript library with Importmap-rails?
How to add an external JavaScript library with Importmap-rails?
답변
The bin/importmap pin command adds a JavaScript library to the config/importmap.rb file. This command automatically resolves the package from jspm.io or a CDN and adds the corresponding mapping. For example, bin/importmap pin lodash adds the pin line for lodash pointing to the CDN.
3Which Rails helper to use for including JavaScript scripts defined in the importmap?
Which Rails helper to use for including JavaScript scripts defined in the importmap?
답변
The javascript_importmap_tags helper generates the necessary tags to load the importmap and JavaScript entry point. It produces a script tag type='importmap' containing the mappings, as well as a tag to load the application.js file. This helper replaces javascript_pack_tag used with Webpacker.
What is the main difference between jsbundling-rails and cssbundling-rails?
What is the main role of Turbo Drive in Hotwire?
+15 면접 질문