如何使用webpack添加jquery插件? [英] How to add jquery plugins using webpack?

查看:342
本文介绍了如何使用webpack添加jquery插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Web应用程序中使用的是角度为2的webpack,所以我需要向我的应用程序中添加一个jquery滑块,因此我为此使用了一个jquery插件.

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 .

我的jquery的webpack配置为

My webpack config for jquery is

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

ProvidePlugin上方为我的应用程序提供了$和jQuery,但是我还需要将jquery插件导入到我的应用程序中

above ProvidePlugin gives $ and jQuery to all over my app , but i need to import the jquery plugin also to my app

推荐答案

通常,将在需要的地方(而不是全局地)导入jQuery插件.

Normally a jQuery plugin would be imported where required, rather than globally.

例如:

import 'jquery.waterwheelCarousel.min.js';

这将导致插件文件被加载,并且由于jQuery在全球范围内提供,因此应使插件函数在jQuery对象($("#carousel").waterwheelCarousel())上可用

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())

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

If you want to made it globally available instead, look at https://webpack.github.io/docs/configuration.html#entry

这篇关于如何使用webpack添加jquery插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆