importmap-rails 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -0
- data/app/assets/javascripts/es-module-shims.js +793 -784
- data/app/assets/javascripts/es-module-shims.js.map +1 -1
- data/app/assets/javascripts/es-module-shims.min.js +1 -1
- data/lib/importmap/map.rb +14 -11
- data/lib/importmap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53d756788e46fd583d5f4dc1b813f11b8479237e766a556fbcbabebf4285ffdd
|
4
|
+
data.tar.gz: 640b9d1cce345d5193e12f17400c772532ddbc4fd97488567e9988eb3ac81fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77a669609b58956d33610ebf3053e0ebe73bdfc1d79d1580df70f1f4d60f96ff92fec0dd0484bac01fe9ed678aac48a07da45402d0209c8a1869a3aece8db85a
|
7
|
+
data.tar.gz: 35e0355d199c75f066f6ce2bea61ceceec0d25e15b6cf10b5d1a052b583580413ab99c104a8a11435d72841b1675815d7535d3c44c976e51a2f3bf6e7910677e
|
data/README.md
CHANGED
@@ -224,6 +224,41 @@ pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
|
|
224
224
|
```
|
225
225
|
|
226
226
|
|
227
|
+
## Selectively importing modules
|
228
|
+
|
229
|
+
You can selectively import your javascript modules on specific pages.
|
230
|
+
|
231
|
+
Create your javascript in `app/javascript`:
|
232
|
+
|
233
|
+
```js
|
234
|
+
// /app/javascript/checkout.js
|
235
|
+
// some checkout specific js
|
236
|
+
```
|
237
|
+
|
238
|
+
Pin your js file:
|
239
|
+
|
240
|
+
```rb
|
241
|
+
# config/importmap.rb
|
242
|
+
# ... other pins...
|
243
|
+
pin "checkout"
|
244
|
+
```
|
245
|
+
|
246
|
+
Import your module on the specific page. Note: you'll likely want to use a `content_for` block on the specifc page/partial, then yield it in your layout.
|
247
|
+
|
248
|
+
```erb
|
249
|
+
<% content_for :head do %>
|
250
|
+
<%= javascript_import_module_tag "checkout" %>
|
251
|
+
<% end %>
|
252
|
+
```
|
253
|
+
|
254
|
+
**Important**: The `javacript_import_module_tag` should come after your `javascript_importmap_tags`
|
255
|
+
|
256
|
+
```erb
|
257
|
+
<%= javascript_importmap_tags %>
|
258
|
+
<%= yield(:head) %>
|
259
|
+
```
|
260
|
+
|
261
|
+
|
227
262
|
## Include a digest of the import map in your ETag
|
228
263
|
|
229
264
|
If you're using [ETags](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) generated by Rails helpers like `stale?` or `fresh_when`, you need to include the digest of the import map into this calculation. Otherwise your application will return 302 cache responses even when your JavaScript assets have changed. You can avoid this with something like:
|