diff --git a/build/rollup-config.js b/build/rollup-config.js index 1a48ad6e8..f91cac067 100644 --- a/build/rollup-config.js +++ b/build/rollup-config.js @@ -12,15 +12,24 @@ const watch = process.argv.indexOf('-w') > -1 || process.argv.indexOf('--watch') const version = release ? pkg.version : `${pkg.version}+${gitRev.branch()}.${gitRev.short()}`; const banner = createBanner(version); +const outro = `var oldL = window.L; +exports.noConflict = function() { + window.L = oldL; + return this; +} +// Always export us to window global (see #2364) +window.L = exports;`; + /** @type {import('rollup').RollupOptions} */ const config = { - input: 'src/LeafletWithGlobals.js', + input: 'src/Leaflet.js', output: [ { file: pkg.main, format: 'umd', name: 'leaflet', banner: banner, + outro: outro, sourcemap: true, freeze: false, esModule: false @@ -34,7 +43,7 @@ const config = { if (!watch) { config.output.push( { - file: pkg.module, + file: 'dist/leaflet-src.esm.js', format: 'es', banner: banner, sourcemap: true, diff --git a/debug/tests/esm.html b/debug/tests/esm.html deleted file mode 100644 index 8c8c04827..000000000 --- a/debug/tests/esm.html +++ /dev/null @@ -1,19 +0,0 @@ - -
- - - - - - - - diff --git a/package.json b/package.json index b447cb0a8..0b399640d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "uglify-js": "^3.17.0" }, "main": "dist/leaflet-src.js", - "module": "dist/leaflet-src.esm.js", "style": "dist/leaflet.css", "files": [ "dist", @@ -70,8 +69,7 @@ ], "root": true, "globals": { - "L": true, - "globalThis": true + "L": true }, "env": { "commonjs": true, diff --git a/spec/karma.conf.js b/spec/karma.conf.js index 58b491a4b..f08226b19 100644 --- a/spec/karma.conf.js +++ b/spec/karma.conf.js @@ -1,5 +1,14 @@ var json = require('@rollup/plugin-json'); +const outro = `var oldL = window.L; +exports.noConflict = function() { + window.L = oldL; + return this; +} + +// Always export us to window global (see #2364) +window.L = exports;`; + // Karma configuration module.exports = function (config) { @@ -7,7 +16,7 @@ module.exports = function (config) { var files = [ "spec/before.js", - "src/LeafletWithGlobals.js", + "src/Leaflet.js", "spec/after.js", "node_modules/happen/happen.js", "node_modules/prosthetic-hand/dist/prosthetic-hand.js", @@ -19,7 +28,7 @@ module.exports = function (config) { var preprocessors = {}; - preprocessors['src/LeafletWithGlobals.js'] = ['rollup']; + preprocessors['src/Leaflet.js'] = ['rollup']; config.set({ // base path, that will be used to resolve files and exclude @@ -55,6 +64,7 @@ module.exports = function (config) { output: { format: 'umd', name: 'leaflet', + outro: outro, freeze: false, }, }, diff --git a/src/LeafletWithGlobals.js b/src/LeafletWithGlobals.js deleted file mode 100644 index 5e59331db..000000000 --- a/src/LeafletWithGlobals.js +++ /dev/null @@ -1,24 +0,0 @@ -import * as L from './Leaflet'; -export * from './Leaflet'; - -var globalL = L.extend(L, {noConflict: noConflict}); -export default globalL; - -var globalObject = getGlobalObject(); -var oldL = globalObject.L; - -globalObject.L = globalL; - -export function noConflict() { - globalObject.L = oldL; - return globalL; -} - -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.'); -}