Open chrisedington opened 3 years ago
To access $
, you need to config jQuery in config/webpack/environment.js
like this
const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery'
})
)
The only way I have found so far to make this work is by copying the javascript file (filterrific-jquery.js) to the packs folder and adding the following to the application.js file...
import { Filterrific } from './filterrific-jquery'; global.Filterrific = Filterrific;
if I point to the filterrific/filterrific-jquery file directly I get it cannot find the module. Anyone else have luck with this?
John
Wondering if anyone has had any luck getting things running with Rails 6 and Webpacker?
I'm confused about the following:
I've added it under 'packs' and then included it into application.js using
require("packs/filterrific-jquery.js");
but it doesn't want to work. I get'Uncaught ReferenceError: $ is not defined'
.Related to above, I normally put the following code into a .js.erb file with the same name as my main view:
I moved this into my view file as it wasn't being triggered by the .js.erb file -- but again run into the
'Uncaught ReferenceError: $ is not defined'
. I have jQuery in my yarn as well as application.js -- sample below:Would really appreciate any feedback or ideas as to what I can try here and the best practice - cant see anything on StackOverflow/other issues.