In a Rails 7 app using import maps, you add a new JavaScript package to config/importmap.rb but do not pin it. What will happen when you try to use it in your JavaScript code?
import { example } from 'new-package' example()
Think about how import maps tell the browser where to find packages.
If a package is not pinned in importmap.rb, the browser does not know where to load it from, causing a 404 error.
Choose the correct way to pin the lodash package from a CDN in config/importmap.rb.
Look for the correct method signature and keyword arguments.
The correct syntax uses pin "package_name", to: "url" with double quotes and the to: keyword.
Given this config/importmap.rb snippet, why does the browser fail to load custom.js?
pin "custom", to: "app/javascript/custom.js"
Think about how import maps resolve local files relative to the JavaScript root.
Import maps expect local files to be referenced relative to app/javascript. Including the folder name duplicates the path.
bin/importmap json in a Rails 7 app?After pinning packages in config/importmap.rb, you run bin/importmap json. What does this command do?
Consider what a JSON output of an import map would represent.
The command prints the import map as JSON so you can see which packages are pinned and their URLs.
Which of the following is the strongest reason to prefer import maps instead of bundlers like Webpack in a Rails 7 project?
Think about what bundlers require compared to import maps.
Import maps let you load JavaScript modules directly in the browser without compiling or bundling, making setup simpler.