README.md in importmap-rails-0.5.1 vs README.md in importmap-rails-0.5.2
- old
+ new
@@ -36,11 +36,11 @@
You can use the `./bin/importmap` command that's added as part of the install to pin, unpin, or update node packages in your import map. This command uses an API from [JSPM.org](https://jspm.org) to resolve your package dependencies efficiently, and then add the pins to your `config/importmap.rb` file. It can resolve these dependencies from JSPM itself, but also from other CDNs, like [unpkg.com](https://unpkg.com) and [jsdelivr.com](https://www.jsdelivr.com).
It works like so:
```bash
-/bin/importmap pin react react-dom
+./bin/importmap pin react react-dom
Pinning "react" to https://ga.jspm.io/npm:react@17.0.2/index.js
Pinning "react-dom" to https://ga.jspm.io/npm:react-dom@17.0.2/index.js
Pinning "object-assign" to https://ga.jspm.io/npm:object-assign@4.1.1/index.js
Pinning "scheduler" to https://ga.jspm.io/npm:scheduler@0.20.2/index.js
@@ -139,9 +139,35 @@
# will include the following link before the importmap is setup:
<link rel="modulepreload" href="https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js">
...
```
+## Composing import maps
+
+By default, Rails loads import map definition from the application's `config/importmap.rb` to the `Importmap::Map` object available at `Rails.application.config.importmap`.
+
+You can combine multiple import maps by drawing their definitions onto the `Rails.application.config.importmap`. For example, appending import maps defined in Rails engines:
+
+```ruby
+# my_engine/lib/my_engine/engine.rb
+
+module MyEngine
+ class Engine < ::Rails::Engine
+ # ...
+ initializer "my-engine.importmap" do |app|
+ app.config.importmap.draw(Engine.root.join("config/importmap.rb"))
+ end
+ end
+end
+```
+
+And pinning JavaScript modules from the engine:
+
+```ruby
+# my_engine/config/importmap.rb
+
+pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
+```
## Caching the import map and preload modules
The import map should be cached in production, and is so by default via the `config.importmap.cached` option that will be set to the same value as `config.action_controller.perform_caching`, unless explicitly set differently.