I'm moving a Rails 6 app from webpack & webpacker to esbuild & jsbundling-rails
I can't find any documentation on the correct way to import custom js files in application.js, if not using stimulus. Thanks.
I'm moving a Rails 6 app from webpack & webpacker to esbuild & jsbundling-rails
I can't find any documentation on the correct way to import custom js files in application.js, if not using stimulus. Thanks.
Copyright © 2021 Jogjafile Inc.
Verifying Set Up
Once the jsbundling-rails gem is added to the Gemfile
gem "jsbundling-rails"
and installed (see the documentation on the repo for installation), you may need to start the javascript watcher with the commandyarn build --watch
.Adding Custom JavaScript
You can add custom JavaScript to the /app/javascript directory and then link it on the application.js. Once the custom javascript is added, the bundler should compile the new fingerprinted javascript file in the /app/assets/build directory.
Example
Adding
new.js
to the /app/javascriptLinking new.js on the application.js
In the terminal which started the watcher, after the new javascript is saved it outputs
And there is now the following files in /app/assets/build