简体   繁体   中英

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.

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.

You will need to require the plugin:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM