Solved

How to include jquery as a global using webpack

Posted on 2016-10-06
1
71 Views
Last Modified: 2016-10-14
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
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41832839
what about ProvidePlugin ?
https://webpack.github.io/docs/shimming-modules.html#plugin-provideplugin

This plugin makes a module available as a variable in every module.
Example: Make $ and jQuery available in every module without writing require("jquery").

Check others notes on top of this page too
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now