0

Is it possible to create a plugin that can be initialized both using jQuery and vanilla Javascript like for example:

// jQuery
$("#selector").plugin({
    option1: "val1",
    option2: "val2"
});

// Javascript
var plugin = plugin("#selector", {
    option1: "val1",
    option2: "val2"
});

But also making sure it can be used via ES6 or CommonJS modules with import plugin from 'plugin.js' or var plugin = require('plugin.js')

Sosa
  • 814
  • 1
  • 9
  • 20
  • Have you tried anything? Have you done any research? What are your findings? Where are you stuck? – Tomalak Dec 05 '17 at 16:05
  • @Tomalak So far i've found [Masonry](https://github.com/desandro/masonry) and [radialIndicator](http://ignitersworld.com/lab/radialIndicator.html) that does something like this. Masonry is hard to understand since it has appears to have some 3rd party wrapper. I think radialindicator might actually be the solution. – Sosa Dec 05 '17 at 16:19
  • The only problem with radialInidicator though is it's a bit awkward to translate getting and setting options/events/methods to be used on both jquery and vanilla javascript initializations. – Sosa Dec 05 '17 at 17:42

1 Answers1

0

I think this is a wider topic, but I recently implemented somehting similar, by using WebPack to instantiate some content using ES6 (If i'm correct Webpack is based on CommonJS if no specific override is set)

To allow, let's say, a plugin to be instanciated with jQuery, I assume a simple wrapper could do the trick.

Kleioz
  • 294
  • 3
  • 13