Reputation: 6674
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?
Upvotes: 4
Views: 510
Reputation: 1244
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.
Upvotes: 2