简体   繁体   English

如何使用webpack添加jquery插件?

[英]How to add jquery plugins using webpack?

I am using webpack with angular 2 for my web appllication i need to add a jquery slider to my app , so i am using a jquery plugin for that . 我在我的Web应用程序中使用的是角度为2的webpack,所以我需要在应用程序中添加一个jquery滑块,因此我为此使用了一个jquery插件。

My webpack config for jquery is 我的jquery webpack配置是

new ProvidePlugin({   
    jQuery: 'jquery',
    $: 'jquery',
    jquery: 'jquery'   
}) 

above ProvidePlugin gives $ and jQuery to all over my app , but i need to import the jquery plugin also to my app 以上ProvidePlugin将$和jQuery提供给了我的整个应用程序,但是我还需要将jquery插件导入到我的应用程序中

Normally a jQuery plugin would be imported where required, rather than globally. 通常,jQuery插件会在需要的地方导入,而不是全局导入。

For example: 例如:

import 'jquery.waterwheelCarousel.min.js';

This will cause the plugin file to be loaded and as jQuery is provided globally, it should cause the plugin function to be made available on the jQuery object ( $("#carousel").waterwheelCarousel() ) 这将导致插件文件被加载,并且由于jQuery是全局提供的,因此应该使插件函数在jQuery对象上可用( $("#carousel").waterwheelCarousel() )。

If you want to made it globally available instead, look at https://webpack.github.io/docs/configuration.html#entry 如果您想使其在全球范围内可用,请查看https://webpack.github.io/docs/configuration.html#entry

in main.ts include 在main.ts中包括

import 'jquery';

once. 一旦。

then in webpack config 然后在webpack配置中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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