importmap-rails 0.6.1 → 0.7.1

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: f7e0d50066c60a35a2490440f039b26f23a34426a5988ad5db9680cf3c436609
4
- data.tar.gz: 630330c8ba8fa300c385d30449a69e8cf88b229a17f16b599b917a7258522bdb
3
+ metadata.gz: 6f178f76220fe01a13e2d79033cabc5261f790102abdd8d0209741cb8c7a6b17
4
+ data.tar.gz: 450c1fd3351c4caf38a88e58ad9c3d9cd25b919c3cafab86e5acbcf977ab6e38
5
5
  SHA512:
6
- metadata.gz: 17082f8ca98917f7d046f62b4c5ed7efb68e72635025397afacdc5ed3fe5b4e048019e1f34e5348c435a609871b7069ae856731389a99687b8167e53ac16040a
7
- data.tar.gz: 929d91e9ad8ae8d75201c08c7b72a56ce85d7774ac1eccfb44df9e22eb4dd3e7667626803ce5bd5c6278b20d0b100ad015534afdabc5ac872ed923da8482b010
6
+ metadata.gz: e119612311447feb13be274fb897a44f1a25d08d12287a66ecd8661638e4884c4f79b6d275e630c0e1661f70a5b9753d57c1e33d8dcbc605a5470fb2add8bc0b
7
+ data.tar.gz: b647688c8a0f634d97d9a3204673cb43eab80086ab3313debce1faee335d0f1abc0e22aada01552fc6f756a9a6233bd64c7dd949933b14fe5beaaa9312679fd4
data/README.md CHANGED
@@ -20,7 +20,7 @@ Note: In order to use JavaScript from Rails frameworks like Action Cable, Action
20
20
 
21
21
  ## Usage
22
22
 
23
- The import map is setup through `Rails.application.config.importmap` via the configuration in `config/importmap.rb`. This file is automatically reloaded in development upon changes, but note that you must restart the server if you remove pins and need them gone from the rendered importmap or list of preloads.
23
+ The import map is setup through `Rails.application.importmap` via the configuration in `config/importmap.rb`. This file is automatically reloaded in development upon changes, but note that you must restart the server if you remove pins and need them gone from the rendered importmap or list of preloads.
24
24
 
25
25
  This import map is inlined in the `<head>` of your application layout using `<%= javascript_importmap_tags %>`, which will setup the JSON configuration inside a `<script type="importmap">` tag. After that, the [es-module-shim](https://github.com/guybedford/es-module-shims) is loaded, and then finally the application entrypoint is imported via `<script type="module">import "application"</script>`. That logical entrypoint, `application`, is mapped in the importmap script tag to the file `app/javascript/application.js`.
26
26
 
@@ -143,9 +143,9 @@ pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js", preload: false
143
143
 
144
144
  ## Composing import maps
145
145
 
146
- 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`.
146
+ By default, Rails loads import map definition from the application's `config/importmap.rb` to the `Importmap::Map` object available at `Rails.application.importmap`.
147
147
 
148
- 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:
148
+ You can combine multiple import maps by drawing their definitions onto the `Rails.application.importmap`. For example, appending import maps defined in Rails engines:
149
149
 
150
150
  ```ruby
151
151
  # my_engine/lib/my_engine/engine.rb
@@ -175,10 +175,16 @@ If you're using etags generated by Rails helpers like `stale?` or `fresh_when`,
175
175
 
176
176
  ```ruby
177
177
  class ApplicationController < ActionController::Base
178
- etag { Rails.application.config.importmap.digest(resolver: helpers) if request.format&.html? }
178
+ etag { Rails.application.importmap.digest(resolver: helpers) if request.format&.html? }
179
179
  end
180
180
  ```
181
181
 
182
+
183
+ ## Sweeping the cache in development and test
184
+
185
+ 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`. If you're pinning local files from outside of `app/javascript`, you'll need to restart your development server upon changes.
186
+
187
+
182
188
  ## Expected errors from using the es-module-shim
183
189
 
184
190
  While import maps are native in Chrome and Edge, they need a shim in other browsers that'll produce a JavaScript console error like `TypeError: Module specifier, 'application' does not start with "/", "./", or "../".`. This error is normal and does not have any user-facing consequences.
@@ -189,6 +195,11 @@ While import maps are native in Chrome and Edge, they need a shim in other brows
189
195
  Under certain circumstances, like running system tests using chromedriver under CI (which may be resource constrained and trigger errors in certain cases), you may want to explicitly turn off including the shim. If can do this by calling the bulk tag helper with `javascript_importmap_tags("application", shim: false)`. Thus you can pass in something like `shim: !ENV["CI"]`. If you want, and are sure you're not doing any full-page caching, you can also connect this directive to a user agent check (using a gem like `useragent`) to check whether the browser is chrome/edge 89+. But you really shouldn't have to, as the shim is designed to gracefully work with natively compatible drivers.
190
196
 
191
197
 
198
+ ## A note about browser extensions
199
+
200
+ Certain extensions that also load Javascript modules may block import maps from being loaded (for instance, the Apollo Client Devtools extension). If you see a console message like `An import map is added after module script load was triggered`, browser extensions are likely the culprit.
201
+
202
+
192
203
  ## License
193
204
 
194
205
  Importmap for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).