Initializers & the asset pipeline
When refactoring or adding new functionality that lives in the asset pipeline, strongly consider moving it to Packs and Webpacker.
application.js automatically includes all JS files via the statement:
//= require_tree .
One JS file in particular,
All the "initializers" are in
Another example of an initializer is
initializeArticleReactions.js which fetches reaction counts and adds click listeners. It adds interactivity to buttons in
It's useful to note that some html.erb views reference function names directly, e.g.
base.js.erb concatenates all the files together and gives us
base.js in production/development environments.