Avatar of Rohit Bajaj
Rohit Bajaj
Flag for India

asked on 

How to include jquery as a global using webpack

Hi,
I am using webpack in my web application for bundling client side code  :
In a new.js file  which is the main file inside which i want to bundle everything :
I am loading jquery like   :
var $ = require(jquery)
installed it via npm install jquery

also in new.js
i am including files like
var util = require(util.js)
And inside util.js  i am using $ directly without importing the jquery

On loading my web application its throwing an error in console :
new.js:512Uncaught ReferenceError: $ is not defined
This is happening because $ is only available directly under new.js and util.js is not declaring jquery which i dont want also as otherwise jquery will get bundled twice.
How do i make $ available to all the libraries i am importing later in the js file... ?

Thanks
jQueryJavaScriptWeb ApplicationsWeb Development

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon