Comments (5)
@cdauth this happens because of javascript hoisting.
this line:
var window = (window || {});
is interpreted as
var window; window = (window || {});
so you don't get the global window varaible.
you can solve it with some hacking:
imports-loader?window=>global&window.jQuery=>jquery!angular
or
imports-loader?windowTemp=>window&windowTemp.jQuery=>jquery!angular
from imports-loader.
I am using exactly the same expression, but for me the imports-loader additionally inserts the some code into the angular module itself:
/* 5 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var window = (window || {});
window.jQuery = __webpack_require__(3);
/**
* @license AngularJS v1.6.1
* (c) 2010-2016 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window) {'use strict';
For some reason though, this window
object is broken and for example doesn't contain document
. I don't really understand why, I will try to investigate.
from imports-loader.
You can provide jQuery by adding plugin:
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jQuery"
})
]
from imports-loader.
After the release, you can solve this problem like this:
module.exports = {
module: {
rules: [
{
test: require.resolve('example.js'),
use: [
{
loader: 'imports-loader',
options: {
type: 'commonjs',
imports: {
moduleName: 'jquery',
name: 'jQuery',
},
aditionalCode: 'window.jQuery = jQuery';
},
},
],
},
],
},
};
// Adds the following code to the beginning of example.js:
//
// var jQuery = require("jquery");
// window.jQuery = jQuery
Release will be soon.
from imports-loader.
@cap-Bernardito thanks for your last comment. There is a little typo in it which you might want to correct. "additionalCode"
Thank you.
from imports-loader.
Related Issues (20)
- imports-loader doesn't generate source maps by default HOT 12
- Can't resolve 'window' in 'project/node_modules/jquery/dist' HOT 15
- regex syntax typo HOT 1
- This line `toString` should be `toJSON` HOT 5
- Allow "import" instead of "require" HOT 5
- Allow import for side effects only HOT 3
- imports-loader doesn't work in combination with expose-loader HOT 1
- Require local file for complex shimming ?
- Using the imports-loader in a require statement ignores "externals" configuration HOT 2
- Can this be used to add a require with inline loaders? HOT 1
- Warning of exports not found after Babel 7 upgrade HOT 6
- loader: require.resolve('imports-loader') instead of use 'imports-loader' HOT 1
- Import config object
- Request for Improved Readme HOT 1
- README: add Inline `additionalCode` example HOT 2
- define=>false in 0.8.0 doesn't work in 1.1.0 HOT 3
- Invalid regular expression: invalid group specifier name HOT 4
- 'import' and 'export' may only appear at the top level HOT 2
- when config 'imports-loader?this=>window' throw "options has an unknown property 'this'" HOT 2
- Who to use imports-loader?this=>window HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imports-loader.