Files
leaflet/build/rollup-config.js
Jon Koops 7ac98758d4 Drop UMD and make ESM the default entrypoint (#8826)
Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Florian Bischof <design.falke@gmail.com>
2025-03-17 15:59:00 +01:00

52 lines
1.4 KiB
JavaScript

import json from '@rollup/plugin-json';
import {readFileSync} from 'node:fs';
import rollupGitVersion from 'rollup-plugin-git-version';
import {simpleGit} from 'simple-git';
// TODO: Replace this with a regular import when ESLint adds support for import assertions.
// See: https://rollupjs.org/guide/en/#importing-packagejson
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)));
const release = process.env.NODE_ENV === 'release';
const version = await getVersion();
const banner = createBanner(version);
/** @type {import('rollup').RollupOptions} */
const config = {
input: 'src/LeafletWithGlobals.js',
output: [
{
file: pkg.exports['.'],
format: 'es',
banner,
sourcemap: true,
freeze: false
}
],
plugins: [
release ? json() : rollupGitVersion()
]
};
export default config;
async function getVersion() {
// Skip the git branch+rev in the banner when doing a release build
if (release) {
return pkg.version;
}
const git = simpleGit();
const branch = (await git.branch()).current;
const commit = await git.revparse(['--short', 'HEAD']);
return `${pkg.version}+${branch}.${commit}`;
}
export function createBanner(version) {
return `/* @preserve
* Leaflet ${version}, a JS library for interactive maps. https://leafletjs.com
* (c) 2010-${new Date().getFullYear()} Volodymyr Agafonkin, (c) 2010-2011 CloudMade
*/
`;
}