[英]How to import a jQuery plugin into a babel app
So I have a modern javascript app build using ES6 modules and transpiled by babel. 因此,我有一个使用ES6模块并由babel编译的现代javascript应用程序构建。
In this app, I need to use a jQuery plugin for some DOM manipulations. 在此应用中,我需要使用jQuery插件进行某些DOM操作。 I don't want to globally expose jQuery and then load the plugin code into the document using a script tag.
我不想全局公开jQuery,然后使用脚本标签将插件代码加载到文档中。 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. 当然,插件不是模块,在实例化时需要
$
变量存在。
You will need to require the plugin: 您将需要插件:
import $ from 'jquery';
require('path-to-plugin');
$('#element').pluginName();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.