[英]webpack imports-loader to window.variable
I'm working on a project with jQuery and Angular. 我正在使用jQuery和Angular开发一个项目。 Specifically, it relies on Angular loading with window.jQuery so that jqLite is replaced.
具体来说,它依赖于使用window.jQuery的Angular加载,以便替换jqLite。 Here's the relevant line of the Angular library:
这是Angular库的相关行:
jQuery = isUndefined(jqName) ? window.jQuery
https://github.com/angular/angular.js/blob/master/src/Angular.js#L1705 https://github.com/angular/angular.js/blob/master/src/Angular.js#L1705
My config for Angular looks like this: 我对Angular的配置如下所示:
loader: "imports-loader?jQuery=jquery,this=>window"
However, it seems that this
is undefined in that particular scope: 然而,似乎
this
是在特定的范围不确定的:
> console.log(this)
undefined
I also tried this, but it raises a parsing error on the .
我也试过这个,但是它引发了一个解析错误
.
in webpack. 在webpack中。
loader: "imports-loader?window.jQuery=jquery"
Here's the config I found that ended up working for me: 这是我发现最终为我工作的配置:
plugins: [
new webpack.ProvidePlugin({
"window.jQuery": "jquery"
})
]
Source: https://github.com/webpack/webpack/issues/542 资料来源: https : //github.com/webpack/webpack/issues/542
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.