importmap-rails 0.8.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 176d828b6f6ec7ca4699eac705589d6bcc9f2803869c1306af59e4fe7af4cb9e
4
- data.tar.gz: 4c134d49d6b55ae72a9d4400d04cbb83c821d4725f51f330cdd5eab0c1e2fd2d
3
+ metadata.gz: f918e23d26d5143a331af11f787bf21e8f05faa0eb6b37bd224eecb83bc2eb1d
4
+ data.tar.gz: cb925e10a5219501ea16f065b21ae96838eeac65b8555aea796331f01a6c0b04
5
5
  SHA512:
6
- metadata.gz: 7cb81efd8cf84fc38ed74902df4dfd3af0be117681cae3d257fcd33ac0a4c2c8a2aa48e3554d14c2116480c281814f0d04c58281970e3b51578d4e83e8226b6d
7
- data.tar.gz: 17412608ef53d81037e8fadac329e3d068eb3afebfd727f5f5af8afb5353d6ed842f277ab8726707619b4c2825766d188be950624bfe6306e816b6ac25ff8b24
6
+ metadata.gz: 9ae8ef2048023b5f761eb4d3b9b9b16ecf7cba30b25a6e7581acf70f3d113ab8658554a962ee162151caebacb37ccb8b2ee9f7604f679fe411f437ad1b38f42c
7
+ data.tar.gz: aff89a7331f5c6702c4f02701a3f8ccb89be944d35c4dc34385b9fbe81384dd73dcc62aa26f73e6d823c12af5ebc39a914b59e51d36667dff2b46ee3436af849
data/README.md CHANGED
@@ -9,7 +9,7 @@ There's [native support for import maps in Chrome/Edge 89+](https://caniuse.com/
9
9
 
10
10
  ## Installation
11
11
 
12
- Importmap for Rails is automatically included in Rails 7+ for new applications, but you can also install it manually in existing applications:
12
+ Importmap for Rails is automatically included in Rails 7+ for new applications, but you can also install it manually in existing applications:
13
13
 
14
14
  1. Add `importmap-rails` to your Gemfile with `gem 'importmap-rails'`
15
15
  2. Run `./bin/bundle install`
@@ -43,7 +43,7 @@ For example:
43
43
 
44
44
  ```rb
45
45
  # config/importmaps.rb
46
- pin "react" to "https://ga.jspm.io/npm:react@17.0.2/index.js"
46
+ pin "react", to: "https://ga.jspm.io/npm:react@17.0.2/index.js"
47
47
  ```
48
48
 
49
49
  means "everytime you see `import React from "react"`
@@ -188,7 +188,7 @@ pin "@github/hotkey", to: "https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/inde
188
188
  pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
189
189
 
190
190
  # app/views/layouts/application.html.erb
191
- <%= javascript_importmap_tags %>
191
+ <%= javascript_importmap_tags %>
192
192
 
193
193
  # will include the following link before the importmap is setup:
194
194
  <link rel="modulepreload" href="https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js">
@@ -199,7 +199,7 @@ pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
199
199
 
200
200
  By default, Rails loads import map definition from the application's `config/importmap.rb` to the `Importmap::Map` object available at `Rails.application.importmap`.
201
201
 
202
- You can combine multiple import maps by drawing their definitions onto the `Rails.application.importmap`. For example, appending import maps defined in Rails engines:
202
+ You can combine multiple import maps by adding paths to additional import map configs to `Rails.application.config.importmap.paths`. For example, appending import maps defined in Rails engines:
203
203
 
204
204
  ```ruby
205
205
  # my_engine/lib/my_engine/engine.rb
@@ -207,8 +207,9 @@ You can combine multiple import maps by drawing their definitions onto the `Rail
207
207
  module MyEngine
208
208
  class Engine < ::Rails::Engine
209
209
  # ...
210
- initializer "my-engine.importmap", after: "importmap" do |app|
211
- app.importmap.draw(Engine.root.join("config/importmap.rb"))
210
+ initializer "my-engine.importmap", before: "importmap" do |app|
211
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
212
+ # ...
212
213
  end
213
214
  end
214
215
  end
@@ -238,14 +239,19 @@ end
238
239
 
239
240
  Generating the import map json and modulepreloads may require resolving hundreds of assets. This can take a while, so these operations are cached, but in development and test, we watch for changes to both `config/importmap.rb` and files in `app/javascript` to clear this cache. This feature can be controlled in an environment configuration file via the boolean `config.importmap.sweep_cache`.
240
241
 
241
- If you're pinning local files from outside of `app/javascript`, you'll need to add them to the cache sweeper configuration or restart your development server upon changes to those external files. To add them to the configuration to clear the cache on changes, for instance when locally developing an engine, use an initializer like the following sample `config/initializers/importmap-caching.rb`:
242
+ If you're pinning local files from outside of `app/javascript`, you'll need to add them to the cache sweeper configuration or restart your development server upon changes to those external files. For example, here's how you can do it for Rails engine:
242
243
 
243
244
  ```ruby
244
- if Rails.env.development?
245
- Rails.application.importmap.cache_sweeper watches: [
246
- Rails.application.root.join("app/javascript"),
247
- MyEngine::Engine.root.join("app/assets/javascripts"),
248
- ]
245
+ # my_engine/lib/my_engine/engine.rb
246
+
247
+ module MyEngine
248
+ class Engine < ::Rails::Engine
249
+ # ...
250
+ initializer "my-engine.importmap", before: "importmap" do |app|
251
+ # ...
252
+ app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascripts")
253
+ end
254
+ end
249
255
  end
250
256
  ```
251
257