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

magicspon
  • 926
  • 2
  • 9
  • 28
  • 2
    No there isn't, you'd have to export the plugin, and still attach it to the jQuery prototype etc. – adeneo Jan 28 '16 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 – magicspon Jan 28 '16 at 19:49
  • Just found this: http://stackoverflow.com/questions/33353406/getting-referenceerror-jquery-is-not-defined-for-package-install-on-npm – magicspon Feb 03 '16 at 14:18

1 Answers1

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).

Community
  • 1
  • 1
DevGrowth.Tech
  • 1,523
  • 17
  • 23