Solved

How to include jquery as a global using webpack

Posted on 2016-10-06
1
178 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
"Go Fund Me" type plugin 5 24
multiple selects 23 48
How to make a good PHP + MySQL + JS pagination system? 3 33
Can't get page to reload 9 10
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

838 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