Solved

How to include jquery as a global using webpack

Posted on 2016-10-06
1
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

756 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