How to import a jQuery plugin into a babel app

雨燕双飞 提交于 2019-12-24 18:23:04

问题


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

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.


回答1:


You will need to require the plugin:

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

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


来源:https://stackoverflow.com/questions/52118452/how-to-import-a-jquery-plugin-into-a-babel-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!