slutske22 / leaflet-arrowheads

A small plugin for leaflet to quickly draw arrowheads on polylines for vector visualization
https://codesandbox.io/s/leaflet-arrowheads-example-zfxxc
MIT License
163 stars 29 forks source link

[Feature request] Proper exports (not only ESM) #48

Closed Scavanger closed 4 months ago

Scavanger commented 4 months ago

For Leaflet plugins its common to define AMD, CommonJS and ESM exports. It just needs this wrapper around the Code:

(function (factory, window) {
    /*globals define, module, require*/

    // define an AMD module that relies on 'leaflet'
    if (typeof define === 'function' && define.amd) {
        define(['leaflet'], factory);

    // define a Common JS module that relies on 'leaflet'
    } else if (typeof exports === 'object') {
        module.exports = factory(require('leaflet'));
    }

    // attach your plugin to the global 'L' variable
    if(typeof window !== 'undefined' && window.L){
        factory(window.L);
    }

}(function (L) {

    // L. ... 
}, window));
slutske22 commented 4 months ago

I would say in the year 2024, that is no longer common in our ES6+ world. For this plugin, just doing an import 'leaflet-arrowheads' will attach all the arrowheads code to the global L object already. Are you working in an ES5 codebase? If so, I'd recommend just grabbing the source code for this plugin from the repo and using it however it makes sense to you, or following the "Without ES6 Imports" section in the README.

Adding compatibility for something like this is not a high priority for me ATM. Closing as a "won't do."