0
0
Ruby on Railsframework~5 mins

Import maps (Rails 7+) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an import map in Rails 7+?
An import map is a way to manage JavaScript module imports directly in the browser without needing a bundler. It tells the browser where to find JavaScript files by mapping module names to URLs.
Click to reveal answer
beginner
How does Rails 7+ use import maps to load JavaScript?
Rails 7+ uses import maps to load JavaScript modules by defining mappings in a file called importmap.rb. The browser reads these mappings and loads the modules from specified URLs, often from CDNs or local assets.
Click to reveal answer
intermediate
What command do you run to pin a JavaScript package using import maps in Rails 7+?
You run `bin/importmap pin <package-name>` to add a package to your import map. This command updates the importmap.rb file and downloads the package if needed.
Click to reveal answer
intermediate
Why might you choose import maps over bundlers like Webpack in Rails 7+?
Import maps let you avoid complex bundler setups. They simplify JavaScript management by loading modules directly in the browser, which can speed up development and reduce configuration.
Click to reveal answer
beginner
How do you include the import map in your Rails 7+ HTML layout?
You include `<%= javascript_importmap_tags %>` in your application layout. This helper inserts the necessary script tags for the browser to load the import map and modules.
Click to reveal answer
What file in Rails 7+ typically holds the import map configuration?
Aconfig/routes.rb
Bapp/javascript/application.js
Cconfig/importmap.rb
Dapp/assets/stylesheets/application.css
Which command pins a package to the import map in Rails 7+?
Abin/importmap pin package-name
Bnpm install package-name
Cyarn add package-name
Drails pin package-name
What does the helper `<%= javascript_importmap_tags %>` do in Rails 7+?
AIncludes CSS stylesheets
BLoads JavaScript modules using the import map
CDefines routes for JavaScript files
DCompiles JavaScript into one file
Why might import maps improve development speed in Rails 7+?
AThey avoid the need for a bundler and complex setup
BThey automatically minify CSS
CThey bundle all JavaScript into one file
DThey replace Ruby code with JavaScript
Where do import maps load JavaScript modules from?
AFrom Ruby gems
BOnly from npm registry
COnly from local files
DFrom URLs defined in the import map, including CDNs or local assets
Explain how import maps work in Rails 7+ and why they are useful.
Think about how the browser finds JavaScript files without bundling.
You got /4 concepts.
    Describe the steps to add a new JavaScript package using import maps in Rails 7+.
    Consider the command and how the package becomes available in the app.
    You got /4 concepts.