diff --git a/build/rollup_plugins.ts b/build/rollup_plugins.ts index d2b4bf353d..96b757bc5b 100644 --- a/build/rollup_plugins.ts +++ b/build/rollup_plugins.ts @@ -11,6 +11,8 @@ import strip from '@rollup/plugin-strip'; import {Plugin} from 'rollup'; import {importAssertionsPlugin} from 'rollup-plugin-import-assert'; +import {version} from '../package.json'; + // Common set of plugins/transformations shared across different rollup // builds (main maplibre bundle, style-spec package, benchmarks bundle) @@ -32,6 +34,9 @@ export const plugins = (production: boolean): Plugin[] => [ '_token_stack:': '' } }), + replace({ + '__packageVersion': version, + }), production && strip({ sourceMap: true, functions: ['PerformanceUtils.*', 'Debug.*'] diff --git a/src/index.ts b/src/index.ts index a706d1b9f1..5d41266090 100644 --- a/src/index.ts +++ b/src/index.ts @@ -99,6 +99,13 @@ const exported = { */ clearPrewarmedResources, + /** + * Returns the package version of the library + */ + get version(): string { + return '__packageVersion'; + }, + /** * Gets and sets the number of web workers instantiated on a page with GL JS maps. * By default, it is set to half the number of CPU cores (capped at 6). diff --git a/src/ui/map.ts b/src/ui/map.ts index 0376b39775..34f71574f0 100644 --- a/src/ui/map.ts +++ b/src/ui/map.ts @@ -523,6 +523,13 @@ class Map extends Camera { return this._mapId; } + /** + * Returns the package version of the library + */ + get version(): string { + return '__packageVersion'; + } + /** * Adds an {@link IControl} to the map, calling `control.onAdd(this)`. *