Transpiling Javascript inline in views

I maintain a Rails 6 app with *.html.slim views containing legacy javascript: and coffee: blocks inline in the view files. The app also has Webpacker set up and various Javascript is already loaded elsewhere in the app through a top-level pack.

I am trying to figure out how to replace this legacy JS/Coffeescript with modern ES6 while if possible continuing to declare it where it is right now, inside the *.html.slim views, in order to keep things together. But that code should still get transpiled to be compatible with all browsers. Is it possible? Is this a recommended approach or not?

1 Like