簡體   English   中英

如何使用webpack添加jquery插件?

[英]How to add jquery plugins using webpack?

我在我的Web應用程序中使用的是角度為2的webpack,所以我需要在應用程序中添加一個jquery滑塊,因此我為此使用了一個jquery插件。

我的jquery webpack配置是

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

以上ProvidePlugin將$和jQuery提供給了我的整個應用程序,但是我還需要將jquery插件導入到我的應用程序中

通常,jQuery插件會在需要的地方導入,而不是全局導入。

例如:

import 'jquery.waterwheelCarousel.min.js';

這將導致插件文件被加載,並且由於jQuery是全局提供的,因此應該使插件函數在jQuery對象上可用( $("#carousel").waterwheelCarousel() )。

如果您想使其在全球范圍內可用,請查看https://webpack.github.io/docs/configuration.html#entry

在main.ts中包括

import 'jquery';

一旦。

然后在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