Rails.js.erb templates no longer work with Webpack

I just switched the Rails application to using WebPack for working with assets, etc. It works fine since I have several JS templates in my views directory (* .js.erb). They require jQuery, and since jQuery extends as part of my WebPack packages, it does not work in these templates.

Is there any way to enable these patterns?

+6
source share
2 answers

Well, to do everything, you need to enable jquery using yarn that works with the latest version of rails.

In Rails 5.1, this is done with the new JSP package yarn that you must install first

sudo apt-get install yarn

jQuery:

yarn add jquery

jquery,

//= require rails-ujs
//= require jquery
//= require turbolinks
//= require_tree .

jquery js.erb article

+1

, expose-loader, app/javascript/packs/application.js:

import 'expose-loader?$!jquery'; import 'expose-loader?jQuery!jquery';

0

All Articles