Skip to content

Commit 3c5849a

Browse files
committed
Use nodeResolve() in rollup to import node_modules by name
Refactor global L.symbol use to use imported symbol of same name from "leaflet" import. Update module specifiers to include ".js" where it is a file for consistency. Update package.json to use specific forks of proj4leaflet (module version), leaflet-locatecontrol (module version) Get import of proj4leaflet from specific branch of maps4html/proj4leaflet fork, which may never get merged upstream, but keeps differences in a git repo, at least, instead of in the build script. Update some tests to import the leaflet module directly Create window.L so that protomaps-leaflet will work. Add rollup alias plugin to allow rollup to resove import of 'leaflet' to correct file (Leaflet lacks a "module" key as of 1.9.4) Get import of proj4 from the module code that ships with that project. The maps4html/proj4leaflet fork works with proj4 code as shipped.
1 parent 37d69c1 commit 3c5849a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1752
-4823
lines changed

Gruntfile.js

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = function(grunt) {
22
const Diff = require('diff');
33
const nodeResolve = require('@rollup/plugin-node-resolve');
4+
const alias = require('@rollup/plugin-alias');
45
grunt.initConfig({
56
pkg: grunt.file.readJSON('package.json'),
67
cssmin: {
@@ -49,30 +50,6 @@ module.exports = function(grunt) {
4950
copy : {
5051
main : {
5152
files: [
52-
{
53-
expand: true,
54-
cwd: 'node_modules/leaflet/dist/',
55-
flatten: true,
56-
filter: 'isFile',
57-
src: ['leaflet-src.js'],
58-
dest: 'dist/'
59-
},
60-
{
61-
expand: true,
62-
cwd: 'node_modules/proj4/dist/',
63-
flatten: true,
64-
filter: 'isFile',
65-
src: ['proj4-src.js'],
66-
dest: 'dist/'
67-
},
68-
{
69-
expand: true,
70-
cwd: 'node_modules/proj4leaflet/src/',
71-
flatten: true,
72-
filter: 'isFile',
73-
src: ['proj4leaflet.js'],
74-
dest: 'dist/'
75-
},
7653
{
7754
expand: true,
7855
flatten: true,
@@ -86,28 +63,12 @@ module.exports = function(grunt) {
8663
filter: 'isFile',
8764
src: ['src/pmtilesRules.js'],
8865
dest: 'dist/'
89-
},
90-
{
91-
expand: true,
92-
cwd: 'node_modules/leaflet.locatecontrol/src/',
93-
flatten: true,
94-
filter: 'isFile',
95-
src: ['L.Control.Locate.js'],
96-
dest: 'dist/'
9766
}
9867
],
9968
options: {
10069
process: function (content, srcpath) {
10170
// see patch.diff file for comments on why patching is necessary
102-
if (srcpath.includes('proj4leaflet.js')) {
103-
console.log('PATCHING: ', srcpath);
104-
const patch = grunt.file.read('src/proj4leaflet/patch.diff');
105-
return Diff.applyPatch(content, patch);
106-
} else if (srcpath.includes('proj4-src.js')) {
107-
console.log('PATCHING: ', srcpath);
108-
const patch = grunt.file.read('src/proj4/patch.diff');
109-
return Diff.applyPatch(content, patch);
110-
} else if (srcpath.includes('index.html')) {
71+
if (srcpath.includes('index.html')) {
11172
console.log('MODIFYING: ', srcpath);
11273
var pathToModuleRE = /dist\/mapml\.js/gi;
11374
return content.replace(pathToModuleRE,"./mapml.js");
@@ -172,7 +133,7 @@ module.exports = function(grunt) {
172133
},
173134
clean: {
174135
dist: ['dist'],
175-
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js','dist/mapmlviewer.js'],
136+
tidyup: ['dist/mapmlviewer.js'],
176137
experiments: {
177138
options: {force: true},
178139
src: ['../experiments/dist']
@@ -191,17 +152,27 @@ module.exports = function(grunt) {
191152
}
192153
},
193154
rollup: {
194-
options: {
195-
format: 'es',
196-
plugins: [nodeResolve()],
197-
external: './pmtilesRules.js'
198-
},
199-
main: {
200-
dest: 'dist/mapmlviewer.js',
201-
src: 'src/mapml/index.js' // Only one source file is permitted
202-
}
203-
},
204-
prettier: {
155+
options: {
156+
format: 'es',
157+
plugins: [
158+
nodeResolve(),
159+
alias({
160+
entries: [
161+
{
162+
find: 'leaflet',
163+
replacement: 'leaflet/dist/leaflet-src.esm.js'
164+
}
165+
]
166+
})
167+
],
168+
external: './pmtilesRules.js'
169+
},
170+
main: {
171+
dest: 'dist/mapmlviewer.js',
172+
src: 'src/mapml/index.js' // Only one source file is permitted
173+
}
174+
},
175+
prettier: {
205176
options: {
206177
// https://prettier.io/docs/en/options.html
207178
progress: true

0 commit comments

Comments
 (0)