Drop ESM entrypoint from package (#8493)

This commit is contained in:
Jon Koops
2022-09-29 17:57:35 +02:00
committed by GitHub
parent 822e55765d
commit fc481fdf61
5 changed files with 24 additions and 50 deletions

View File

@ -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,

View File

@ -1,19 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="../../dist/leaflet.css" />
<link rel="stylesheet" href="../css/screen.css" />
</head>
<body>
<div id="map"></div>
<script type="module">
import L from '../../dist/leaflet-src.esm.js';
var map = L.map('map', {
center: [39.84, -96.591],
zoom: 4,
});
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
</script>
</body>
</html>

View File

@ -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,

View File

@ -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,
},
},

View File

@ -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.');
}