Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails .js.erb templates no longer work with Webpack

I've just switched my Rails app over to use WebPack to deal with assets etc. It's working well apart from I have some JS templates in my views directory (*.js.erb) . These require jQuery and as jQuery is pulled in as part of my WebPack bundles, it is not working in those templates.

Is there a way to allow those templates to work?

like image 418
rctneil Avatar asked Nov 19 '17 18:11

rctneil


1 Answers

I got this to work in my app by adding the expose-loader package, then adding these two lines to my app/javascript/packs/application.js:

import 'expose-loader?$!jquery';
import 'expose-loader?jQuery!jquery';
like image 161
lavaturtle Avatar answered Nov 12 '22 13:11

lavaturtle