rlkw1024
rlkw1024

Reputation: 6515

Serving JavaScript files with Rails 7 and esbuild

I am using Rails 7 with esbuild, jsbundling-rails, and importmap-rails. I am using the following command to start the esbuild watcher:

esbuild app/javascript/*.* --bundle --sourcemap --format=esm \
  --outdir=app/assets/builds --public-path=/assets --watch=forever

Most of my JavaScript code is structured as ESM modules. These are not referenced in app/javascript/application.js.

With this setup, I have observed the following:

Some of the above may be the way Rails is designed to work. But I'm clearly doing something wrong, because I can't generate working URLs to any JavaScript files, whether manually or with helpers.

What I would have expected to see is:

I want to follow the most bog-standard conventions for a modern Rails app. I am not wedded to any of the dependencies I have identified above. But I do want some sort of JavaScript build stage (partly so that I can start using TypeScript). Nor am I wedded to compiling into app/assets/builds: I chose that folder only because I understood that to be the convention.

With that in mind, my questions are:

Upvotes: 0

Views: 44

Answers (0)

Related Questions