-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgulpfile.js
More file actions
165 lines (143 loc) · 4.83 KB
/
Copy pathgulpfile.js
File metadata and controls
165 lines (143 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* 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
*/
const gulp = require('gulp');
const { series, parallel } = require('gulp');
const del = require('del');
const concat = require('gulp-concat');
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'
}
const main_styles = [
'./node_modules/leaflet/dist/leaflet.css',
'./node_modules/leaflet.fullscreen/dist/Control.FullScreen.css',
'./node_modules/leaflet-gesture-handling/dist/leaflet-gesture-handling.css',
'./node_modules/leaflet.markercluster/dist/MarkerCluster.css',
'./node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css',
'./node_modules/leaflet-control-geocoder/dist/Control.Geocoder.css',
'./node_modules/leaflet-legend/leaflet-legend.css'
];
const main_scripts = [
'./node_modules/leaflet/dist/leaflet.js',
'./node_modules/leaflet.fullscreen/dist/Control.FullScreen.umd.js',
'./node_modules/leaflet-gesture-handling/dist/leaflet-gesture-handling.min.js',
'./node_modules/leaflet.markercluster/dist/leaflet.markercluster.js',
'./node_modules/leaflet-control-geocoder/dist/Control.Geocoder.js',
'./node_modules/leaflet-legend/leaflet-legend.js'
];
const gl_styles = [
'./node_modules/maplibre-gl/dist/maplibre-gl.css'
];
// 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 = [
{
'src': './node_modules/leaflet/dist/images/*',
'dest': '/images/'
},
{
'src': './node_modules/leaflet.locatecontrol/*.svg',
'dest': '/images/'
},
{
'src': './node_modules/leaflet.fullscreen/*.svg',
'dest': '/images/'
}
];
function clean(cb) {
assets = [
plugin.public + '/**',
'!' + plugin.public,
'!' + plugin.public + '/galette_maps.css',
plugin.public + '/images/**',
'!' + plugin.public + '/images',
'!' + plugin.public + '/images/marker-galette.png',
'!' + plugin.public + '/images/marker-galette-pro.png',
];
return del(assets, cb);
};
function styles() {
main = gulp.src(main_styles)
.pipe(replace('icon-fullscreen.svg', './images/icon-fullscreen.svg'))
.pipe(cleancss())
.pipe(concat('maps-main.bundle.min.css'))
.pipe(gulp.dest(plugin.public));
locate = gulp.src([
'./node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.css'
])
.pipe(replace('../location-arrow-solid.svg', './images/location-arrow-solid.svg'))
.pipe(replace('../spinner-solid.svg', './images/spinner-solid.svg'))
.pipe(cleancss())
.pipe(concat('maps-locate.bundle.min.css'))
.pipe(gulp.dest(plugin.public));
gl = gulp.src(gl_styles)
.pipe(cleancss())
.pipe(concat('maps-gl.bundle.min.css'))
.pipe(gulp.dest(plugin.public));
return merge(main, locate, gl);
};
function scripts() {
main = gulp.src(main_scripts)
.pipe(concat('maps-main.bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest(plugin.public));
locate = gulp.src([
'./node_modules/leaflet.locatecontrol/dist/L.Control.Locate.min.js'
])
.pipe(concat('maps-locate.bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest(plugin.public));
return merge(main, locate);
};
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() {
main = main_assets.map(function (asset) {
return gulp.src(asset.src, {encoding: false})
.pipe(gulp.dest(plugin.public + asset.dest));
}
);
return merge(main);
};
exports.clean = clean;
exports.styles = styles;
exports.scripts = scripts;
exports.gl_scripts = gl_scripts;
exports.assets = assets;
exports.build = series(styles, scripts, gl_scripts, assets);
exports.default = exports.build;