this.jQuery cannot be shimmed with ProvidePlugin
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
The ProvidePlugin does not properly support importing and replacing this.jQuery
in legacy apps.
If the current behavior is a bug, please provide the steps to reproduce.
test.js
if (this.jQuery) {
throw 'Jquery is not available.';
}
console.log('jQuery found.', this.jQuery);
This outputs the following:
webpackJsonp([0],[
/* 0 */
/***/ (function(module, exports) {
if (this.jQuery) {
throw 'Jquery is not available.';
}
console.log('jQuery found.', this.jQuery);
/***/ })
],[0]);
If you were to define it as this2
instead, you get the correct output:
webpackJsonp([0],[
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(__webpack_provided_this2_dot_jQuery) {if (__webpack_provided_this2_dot_jQuery) {
throw 'Jquery is not available.';
}
console.log('jQuery found.', __webpack_provided_this2_dot_jQuery);
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
config
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: {
test: './test.js'
},
output: {
path: path.resolve(__dirname, './output.js'),
filename: '[name].js'
},
plugins: [
new webpack.ProvidePlugin({
'this.jQuery': 'jquery'
})
]
};
What is the expected behavior?
It should replace this.jQuery
with the imported version.
If this is a feature request, what is motivation or use case for changing the behavior?
To support shimming legacy apps that use this
as the global window context.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
Webpack version: 3.11.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Free means not defined in these module. Coming from the environment.
Only the top level this comes from webpack. Every other this is defined in the module.
@sokra, does
free
property meanallowed to be renamed
? I’m actually confused as to whatfree
represents. AlsotopLevelScoped this
representsexported modules from current module
, will it not cause any ambiguity?? Acc. to me, either we should completely support changing this.propertyName to a module using providePlugin(in every scope), or not support it at all. That way, we can be sure that user wants it and it’s developer’s responsibility to not abuse it…