I am trying to get jQuery working in the Phoenix application.
I got the advice from the Phoenix Guide where it instructs me to install the jQuery through NPM.
From the root of the directory
$ npm install --save jquery
In the brunch-config.js, I added the `jquery` to the whitelist.
In the web/static/js/app.js, I added `import $ from "jquery"` but jQuery didn't work.
So, I tried to exports the `$` and `jQuery` in the brunch-config.js file under whitelist section
globals: {
$: "jquery",
jQuery: "jquery"
}
However, it didn't work for me either.
I am able to get it working by placing the jquery.min.js in the web/static/vendor directory.
and in the brunch-config.file, I told Brunch to compile JS to the multiple targets.
joinTo: {
'js/vendor.js': /^(?!app\/)/,
'js/app.js': /^app\//
}
Here is the question, is this a correct thing for me to do? since the Static Assets Guide instructs to use the NPM so that it can resolve the dependency updates automatically.
Please advise and thanks for this wondering web framework.