简体   繁体   中英

webpack imports-loader to window.variable

I'm working on a project with jQuery and Angular. Specifically, it relies on Angular loading with window.jQuery so that jqLite is replaced. Here's the relevant line of the Angular library:

jQuery = isUndefined(jqName) ? window.jQuery

https://github.com/angular/angular.js/blob/master/src/Angular.js#L1705

My config for Angular looks like this:

loader: "imports-loader?jQuery=jquery,this=>window"

However, it seems that this is undefined in that particular scope:

> console.log(this)
undefined

I also tried this, but it raises a parsing error on the . in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM