I am attempting to use ES6 syntax in my Rails 4 app and have had some success between the use of sprockets-es6 (0.9.2)
, sprockets-rails (3.0.4)
and sprockets (3.6.0)
.
The only issue I'm having is that my files need to end in .es6
in order to enable proper compilation and I'd like to be able to use a .es6.erb
or .js.erb
file type to allow me to use embedded ruby <%= foo %>
.
Does anyone know of a way around this?
This question is a few years old and the OP specifies Sprockets 3.6. But I'm guessing many will find this question when looking for a solution to using erb files with a more modern version of sprockets.
If you're using Sprockets 4 and want to use .js.erb
you'll need to 'register_mime_type'.
e.g. add the following to a new file called ./config/initializer/register_mime_type.rb
Sprockets.register_mime_type 'application/javascript', extensions: ['.js.erb']
This is described in Extending Sprockets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With