How to create a gem with rails 7 that packs javascripts for other projects to import

I’m upgrading my projects to rails 7. With esbuild, my projects works fine currently.

But I have lots of custom javascripts which could not be found in npm packages.

Since many projects needs these javascripts, I want to create a gem to pack them up.

My final goal is to simply add this code to my projects:

Gemfile:

gem 'my_js_lib'

application.js:

...
import 'my_js1';
import 'my_js2';
...

that I could use my own packed js libraries without copying them to each project.