Skip to content

Commit

Permalink
Update with pinning modules from engine/gem
Browse files Browse the repository at this point in the history
Since Rails ActionView includes rails-ujs.esm.js, we can import it directly without having to download the file from a CDN.
  • Loading branch information
javierjulio authored Jan 2, 2024
1 parent a4d915b commit c4a504c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c4a504c

Please sign in to comment.