简体   繁体   中英

How could make WebPack load external jQuery and jQuery libs?

I'm working on a project which based on a frontend template with bootstrap.

So in my project, we need load jQuery, jQuery UI and bootstrap and other jQuery plugins in all the pages.

I am new to WebPack, and also did a lot research like to make jQuery exposed to global by webpack.config.js.

But I'm also confusing how to make the other jQuery plugins like bootstrap to be exposed to global as jQuery?

Since this code will make $ as jQuery and works global (when in the entry files tried to use $, jQuery will be included in the entry file automatic).

How can I add other jQuery plugins act like jQuery? (to be included automatic when the entry use $)

The way I used to expose jQuery is create a provideplugin:

  new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", "window.jQuery": "jquery" }), 

You can define the js-file with all needed dependencies that simply return jQuery. Something like this:

var jquery = require('./jquery.js');
require('./jquery.plugin1.js');
require('./jquery.plugin2.js');

module.exports = jquery;

Now you can use this module instead of "jquery" and all your plugins that was defined in it will be available.

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