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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88dca9c2f87f4777a70f6d6e95bf7212c4f7392b04da6571f479c46b65805e28
4
- data.tar.gz: c93c502ef9a4f739fe630bc24052ea4df3e17ce37ee5323a513ad5d302e0d7e1
3
+ metadata.gz: 53d756788e46fd583d5f4dc1b813f11b8479237e766a556fbcbabebf4285ffdd
4
+ data.tar.gz: 640b9d1cce345d5193e12f17400c772532ddbc4fd97488567e9988eb3ac81fd7
5
5
  SHA512:
6
- metadata.gz: e058a2747e3a884535312eed0f21235d6ac98c5e7d8ba2c8cf702f52952b634cca93ec8c66f102168d60d696ab160d3ff9b08945f0419de627e58ae8a5f64633
7
- data.tar.gz: bda6354071b0610aba6e1f7347b533d26a3a624b87038c19b0c8404ec347a37b7e1cffe41b36c4bedd4aa058f4981e359093982ea97b099cb8a1f9c57fd0657c
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: