Skip to content

Global L is exported via ESM #9842

@Falke-Design

Description

@Falke-Design

When generating the dist files, we use the LeafletWithGlobals file. This causes the ESM module to add the global L to the window object. Should we change the export configs?

  • UMD -> LeafletWithGlobals.js (with global L)
  • ESM -> Leaflet.js (without global L)

input: 'src/LeafletWithGlobals.js',
output: [
{
file: pkg.exports['.'],
format: 'es',
banner,
sourcemap: true,
freeze: false
},
{
file: './dist/leaflet-global-src.js',
name: 'leaflet',
format: 'umd',
banner,
sourcemap: true,
freeze: false,
esModule: false
}
],

import * as L from './Leaflet.js';
export * from './Leaflet.js';
export default L;
const oldL = getGlobalObject().L;
getGlobalObject().L = L;
getGlobalObject().L.noConflict = function () {
getGlobalObject().L = oldL;
return this;
};
function getGlobalObject() {
if (typeof globalThis !== 'undefined') { return globalThis; }
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
throw new Error('Unable to locate global object.');
}

https://plnkr.co/edit/7wAJePQI44QmAedQ

@mourner, @IvanSanchez, @jonkoops, @simon04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions