如何将jQuery插件导入babel应用程序 [英] How to import a jQuery plugin into a babel app

查看:163
本文介绍了如何将jQuery插件导入babel应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个使用ES6模块并由babel进行编译的现代javascript应用程序构建.

So I have a modern javascript app build using ES6 modules and transpiled by babel.

在此应用中,我需要使用 jQuery插件进行某些DOM操作.我不想全局公开jQuery,然后使用脚本标签将插件代码加载到文档中.相反,我希望插件仅在模块内部可用:

In this app, I need to use a jQuery plugin for some DOM manipulations. I don't want to globally expose jQuery and then load the plugin code into the document using a script tag. Instead, I want the plugin to be available only inside a module:

import $ from 'jquery';
// some magic importing pluginName

$('#element').pluginName();   // how to make this work? 

当然,插件不是模块,在实例化时它需要$变量出现.

Of course plugin is not a module and it needs the $ variable to be present when instantiating.

推荐答案

您将需要插件:

import $ from 'jquery';
require('path-to-plugin');

$('#element').pluginName();

这篇关于如何将jQuery插件导入babel应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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