Using a module written in ES6

  • I am using a third-party library named leaflet in my custom-plugin's front end JS code.

    Now I need to use a leaflet plugin named leaflet-geosearch which is written in ES6 and it is dependent on a number of other packages like Babel precompiler (that compiles ES6 to ES5 code).

    Can I use it in my client side JS code? If yes, how? How can I set up the environment. Can anybody help me put on the track?

    Thanking you in anticipation.

  • Global Moderator

    The readme on that github explains several options. You can use unpkg to download a single file for it. You can install the npm package and include that in plugin.json.

  • Global Moderator

    Just note that you will need fetch and array.includes support.

  • Thanks Pita I will look into it

    Under what heading in plugin.json, shall I include?

    Is there really a need to install it using npm? I can simply copy that single file in static/lib/... directory and refer to it from the plugin.json. I hope this will do. Pl. confirm.

    This library is written with the latest technologies in mind. Thereby it is required to include some polyfills when you wish to support older browsers. These polyfills are recommended for IE and Safari support:
    babel-polyfill, for array.includes support.
    whatwg-fetch, for fetch requests.

    Ok I got it. How to include support for these two polyfills. Pl. tell me.

  • Global Moderator

    You'll probably want to put it under modules in plugin.json.

    Here's a polyfill for array.includes, you probably don't need all of babel-polyfill:

    Array.prototype.includes = Array.prototype.includes || function includes(value) {
      return this.indexOf(value) !== -1;

  • Thank you for putting me on track once again. Where shall I write this polyfill code ... in my map.js?



Looks like your connection to NodeBB was lost, please wait while we try to reconnect.