fix: resolve Leaflet window.L not being set in esbuild bundle
The esbuild bundle wraps everything in a 'use strict' IIFE, causing the leaflet UMD module to take the CommonJS path instead of setting window.leaflet. The entry point check window.leaflet && !window.L always failed, so window.L was never assigned and the map never initialized. - Add leaflet-global.js to import leaflet-minimal and set window.L before plugins execute (ESM source-order evaluation guarantees this) - Replace the broken window.leaflet check in map-bundle-entry.js with an import of leaflet-global.js
This commit is contained in:
parent
0f50b8aadf
commit
b218f21734
2 changed files with 13 additions and 8 deletions
7
assets/js/leaflet-global.js
Normal file
7
assets/js/leaflet-global.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// Sets window.L from the imported leaflet module.
|
||||
// Required because esbuild bundles everything in a "use strict" IIFE,
|
||||
// causing the leaflet UMD to take the CommonJS path instead of setting
|
||||
// window.leaflet. Plugins and hooks expect window.L to exist.
|
||||
import * as leafletModule from "../vendor/js/leaflet-minimal.js";
|
||||
|
||||
window.L = leafletModule;
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
// Map bundle entry point - combines Leaflet and map plugins
|
||||
import "../vendor/js/leaflet-minimal.js";
|
||||
// Map bundle entry point — combines Leaflet and map plugins.
|
||||
//
|
||||
// ESM evaluates side-effect imports in source order, so leaflet-global.js
|
||||
// runs (and sets window.L) before plugins-optimized.js, which references L.
|
||||
import "./leaflet-global.js";
|
||||
import "../vendor/js/plugins-optimized.js";
|
||||
|
||||
// Ensure Leaflet is available as window.L (standard convention)
|
||||
if (window.leaflet && !window.L) {
|
||||
window.L = window.leaflet;
|
||||
}
|
||||
|
||||
// Mark bundle as loaded
|
||||
window.mapBundleLoaded = true;
|
||||
window.mapBundleLoaded = true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue