package that also includes CSS assets, esbuild does allow you to import those, but will name
The result of that being two files output to
application.css - and that’s where the hang-up occurs. If you are also using cssbundling-rails it will by default name it’s output the same thing -
application.css, causing a naming collision that will inevitably cause you to bang your head against the wall if you aren’t sure what’s going on.
There are two solutions here, one is renaming the output of your
cssbundling-rails file, or renaming your
app/assets/build. Then all you need to do is make sure you include those files in the head of your
If you’re not starting fresh in Rails 7 there’s good chance you’ve got files in
If so you’ll also want to make sure you’ve got sprockets setup to serve those assets. This can be done in
app/assets/config/manifest.js, just make sure you’ve got the following line in the config:
Of course you could also use
link_tree or any of the other methods that sprockets provides in order
including just one file helps keep things clean and easy to understand.
Also note that doing this also assumes that you’ve renamed your esbuild output file to
as mentioned above, otherwise you’d run into similar naming collision issues that Gotcha #1 covers.