[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to include jquery as a global using webpack

Posted on 2016-10-06
1
Medium Priority
?
440 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 2000 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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

656 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