Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def add_libs(rel_name, galette_archive):
if os.path.exists(target):
os.remove(target)

for todrop in ['.github', 'bin', 'node_modules', 'tests']:
for todrop in ['.github', 'bin', 'build', 'node_modules', 'tests']:
target = os.path.join(npm_dir, todrop)
if os.path.exists(target):
shutil.rmtree(target)
Expand Down
10 changes: 10 additions & 0 deletions build/leaflet-global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file is part of Galette Maps plugin (https://galette.eu).
* SPDX-FileCopyrightText: Copyright © 2012-2026 The Galette Team
* SPDX-License-Identifier: GPL-3.0-or-later
*/

// Leaflet is already loaded by maps-main.bundle.min.js; hand the bundler that
// instance instead of a second copy, or the plugin would extend a Leaflet the
// page never sees.
module.exports = window.L;
19 changes: 19 additions & 0 deletions build/maps-gl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This file is part of Galette Maps plugin (https://galette.eu).
* SPDX-FileCopyrightText: Copyright © 2012-2026 The Galette Team
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import * as maplibregl from 'maplibre-gl';
// Registers L.maplibreGL on the Leaflet the page already loaded (see the
// `leaflet` alias in gulpfile.js).
import '@maplibre/maplibre-gl-leaflet';

// The worker is shipped next to this bundle; derive its URL from our own
// <script> so no template has to know where plugin resources are served from.
const bundle_url = document.currentScript && document.currentScript.src;
if (bundle_url) {
maplibregl.setWorkerUrl(new URL('maps-gl.worker.min.js', bundle_url).href);
}

export * from 'maplibre-gl';
49 changes: 36 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const uglify = require('gulp-uglify');
const merge = require('ordered-read-streams');
const replace = require('gulp-replace');
const cleancss = require('gulp-clean-css');
const esbuild = require('esbuild');

const plugin = {
'public': './webroot'
Expand Down Expand Up @@ -41,14 +42,18 @@ const gl_styles = [
'./node_modules/maplibre-gl/dist/maplibre-gl.css'
];

// maplibre-gl is pinned to 5.x on purpose: 6.x dropped the UMD build and ships
// ES modules only, which cannot be concatenated into a classic script. The 5.x
// dist is already minified and uses syntax uglify-js cannot parse, so this
// bundle is concatenated as is, never piped through uglify.
const gl_scripts = [
'./node_modules/maplibre-gl/dist/maplibre-gl.js',
'./node_modules/@maplibre/maplibre-gl-leaflet/leaflet-maplibre-gl.js'
];
// maplibre-gl ships ES modules only since 6.x, so its bundle cannot be built by
// concatenation like the others: esbuild rolls it up, along with the Leaflet
// binding, into a classic script still exposing the `maplibregl` global.
const gl_entry = './build/maps-gl.js';
// Leaflet comes from maps-main.bundle.min.js, so the bundle must reuse the one
// on the page instead of embedding a second copy.
const gl_aliases = {
'leaflet': './build/leaflet-global.js'
};
// maplibre-gl runs its tile parsing in a worker it fetches at runtime; it has to
// be a file of its own, next to the bundle.
const gl_worker = './node_modules/maplibre-gl/dist/maplibre-gl-worker.mjs';

const main_assets = [
{
Expand Down Expand Up @@ -115,11 +120,28 @@ function scripts() {
.pipe(uglify())
.pipe(gulp.dest(plugin.public));

gl = gulp.src(gl_scripts)
.pipe(concat('maps-gl.bundle.min.js'))
.pipe(gulp.dest(plugin.public));
return merge(main, locate);
};

return merge(main, locate, gl);
function gl_scripts() {
return Promise.all([
esbuild.build({
entryPoints: [gl_entry],
outfile: plugin.public + '/maps-gl.bundle.min.js',
bundle: true,
minify: true,
format: 'iife',
globalName: 'maplibregl',
alias: gl_aliases
}),
esbuild.build({
entryPoints: [gl_worker],
outfile: plugin.public + '/maps-gl.worker.min.js',
bundle: true,
minify: true,
format: 'esm'
})
]);
};

function assets() {
Expand All @@ -136,7 +158,8 @@ exports.clean = clean;

exports.styles = styles;
exports.scripts = scripts;
exports.gl_scripts = gl_scripts;
exports.assets = assets;

exports.build = series(styles, scripts, assets);
exports.build = series(styles, scripts, gl_scripts, assets);
exports.default = exports.build;
Loading