Add entrypoint for ES modules to package
See original GitHub issueHi folks,
I’ve been digging around today trying to figure out why Webpack’s tree shaking magic did not appear to be working on Leaflet’s code. Digging back through the history here, I see the following historic PRs:
- February 2018: #6021 adds ES6 Module support, and unlocking all the goodies that come alongside
- March 2018: Leaflet/Leaflet.markercluster#874 is broken due to the lack of a global
L
- July 2018: #6239 was a hotfix removing support for ES6 modules due to the above
In the removal hotfix, there was a comment that “people who want to take advantage of tree shaking can opt-in by adding custom rules resolving Leaflet to dist/leaflet-src.esm.js
.” I’ll freely admit that I’m struggling to figure out how to do that (it may be pretty clear to be fair; I’m really not up to date with the modern Javascript ecosystem.)
Ever since that hotfix, there’s been a few PRs attempting to reintroduce module support but they’ve all been closed with a link back to the removal hotfix, and no further discussion.
The Leaflet/Leaflet.markercluster#874 issue remains open, with recent (January this year) comments floating the ideas of:
- A new major version release of Leaflet to enforce the removal of the
L
global variable - Updating plugins to automatically resolve
L
to theleaflet
module, rather than requiring Leaflet to exposeL
as a global variable.
Beyond this chatter on the Markercluster repo, I haven’t seen any other discussion on how the Leaflet community is feeling about the lack of ES6 module support and the widespread (?) dependence on a global L
. If I may, I’d like to be the one to bring these up for discussion.
Do we know what the remaining blockers are for:
- Removing the global
L
- Bringing back ES6 module support?
And is there anything we can do make progress on these?
Thanks all, Rob
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:38 (4 by maintainers)
Top GitHub Comments
I think we want to drop UMD builds and the global at some point (whether that’s 2.0 or some other future version). To maintain backwards compatibility we can provide a dedicated
leaflet/globals
import to restore the behavior.Personally I’d like to work Leaflet towards an ‘ESM first’ library so that it can simply be imported directly from a web browser. New standards such as Import Maps will make this even easier.
I am not a contributor on this project, so I know I may not hold weight here. You have to remove the global L at some point to move forward. Whatever the solution is, I’m sure the talented people here can figure something out. I realize the plugin issue, but in my own dev world, Leaflet is one of the few libraries out there keeping my development and build pipelines 10 years behind.
And, actually, MANY of the Leaflet plugins I use these days (or the build tools) allow one to import the core objects/classes directly.