2

Evening all,

Is there a simple way to convert an existing jquery plugin to use the es6 import/export syntax.

for example:

import $ from 'jquery';
import cycle from 'plugins/jquery-cycle';

Thanks

3
  • 2
    No there isn't, you'd have to export the plugin, and still attach it to the jQuery prototype etc. Commented Jan 28, 2016 at 12:47
  • Is there a common approach for doing this? With the example above I would still expect to use the 'cycle' plugin attached to the jquery prototype... i.e. $.cycle(); Thanks Commented Jan 28, 2016 at 19:49
  • Just found this: stackoverflow.com/questions/33353406/… Commented Feb 3, 2016 at 14:18

1 Answer 1

1

I tried solutions from this thread with a jQuery plugin(autocomplete), and it works. Although I have to manually change the originally UMD js file to a ES6-ish module. If the third part libraries are complicated or there are too many of them, I don't think this approach is gonna work well.

That being said, you can give other tools a shot depends on the structure of your project. For example, use jspm and systemjs as this thread mentioned. Or use amd-to-es6 to convert file format(although this plugin doesn't seem to work well with UMD js file for now). If you are using rollup to bundle ES6 files, you can add this rollup plugin in rollup config(but it still have some issue with UMD files).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.