Open
Conversation
- Add ESM source in src/leaflet-mapbox-gl.js with import/export syntax
- Set up Rollup to build both ESM and UMD bundles to dist/
- Add package.json exports field for conditional ESM/CJS resolution
- Add "module" field pointing to ESM build
- Add TypeScript type definitions
- Configure JSHint for ES6+ with .jshintrc
- Keep original leaflet-mapbox-gl.js for backwards compatibility
Usage:
- ESM: import { mapboxGL } from 'mapbox-gl-leaflet'
- CJS: const { mapboxGL } = require('mapbox-gl-leaflet')
- Browser: <script src="dist/leaflet-mapbox-gl.js">
There was a problem hiding this comment.
Pull request overview
This PR adds an ES Module (ESM) build alongside the existing UMD distribution, aiming to improve compatibility with modern bundlers/Node ESM while preserving browser/global usage.
Changes:
- Added an ESM source entry (
src/leaflet-mapbox-gl.js) withimport/exportand named/default exports. - Introduced a Rollup build producing
dist/leaflet-mapbox-gl.esm.js(ESM) anddist/leaflet-mapbox-gl.js(UMD). - Updated package metadata/scripts and added TypeScript declarations.
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/leaflet-mapbox-gl.js | New ESM entrypoint that exports MapboxGL / mapboxGL and also mutates L for compatibility. |
| rollup.config.js | Rollup config to emit ESM + UMD builds. |
| package.json | Adds conditional exports, sets type: module, and adds build/lint scripts. |
| package-lock.json | Updates lockfile to include Rollup dependencies and lockfile v3 format. |
| dist/leaflet-mapbox-gl.d.ts | Adds TypeScript typings and Leaflet module augmentation. |
| .jshintrc | Enables ES module linting and modern ECMAScript settings. |
| .gitignore | Ignores generated dist/*.js and sourcemaps while keeping .d.ts tracked. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Rename CJS output to .cjs extension for explicit module type - Add separate UMD build (.umd.js) for browsers - Add "browser" field pointing to UMD build - Update exports to use .cjs for require()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR modernizes the package to support ES Modules (ESM) alongside the existing UMD format, enabling better tree-shaking and native module support in modern bundlers and Node.js.
Changes
src/leaflet-mapbox-gl.js) with nativeimport/exportsyntaxdist/"type": "module"for native ESM"module"field pointing to ESM build"exports"field with conditional exports for ESM/CJS resolution"types"field for TypeScript supportnpm run build,prepublishOnly)dist/leaflet-mapbox-gl.d.ts).jshintrc) updated for ES6+Usage
ESM (modern bundlers/Node.js):
CommonJS:
Browser (unchanged):
Backwards Compatibility
leaflet-mapbox-gl.jsis kept in the package for users referencing it directlyL.mapboxGL/L.MapboxGLglobalsTest plan
npm run lintpassesnpm run buildproduces both ESM and UMD bundles