From c4a504c079542a661bf9b8ce7779b5d43583841e Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Tue, 2 Jan 2024 12:44:28 -0500 Subject: [PATCH] Update with pinning modules from engine/gem Since Rails ActionView includes rails-ujs.esm.js, we can import it directly without having to download the file from a CDN. --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 3e086e3..46d5e19 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,21 @@ And pinning JavaScript modules from the engine: pin_all_from File.expand_path("../app/assets/javascripts", __dir__) ``` +## Pinning modules from engines + +To pin a vendored module from a gem, such as `@rails/ujs` from Rails ActionView, we can import the ESM module: + +```ruby +# config/importmap.rb +pin "@rails/ujs", to: "rails-ujs.esm.js" +``` + +Then update the `app/assets/config/manifest.js` file to link it: + +```js +# ... +//= link rails-ujs.esm.js +``` ## Selectively importing modules