Skip to content

Commit ac6dde9

Browse files
committed
Remove grunt-rollup grunt plugin, replace with customRollup task,
config done via external rollup.config.js. Remove uglify grunt plugin, replace with terser rollup plugin (does a better job with source maps and chained minification) Add nrcan-basemap grunt task for sibling project to get nrcan vector tile basemap working with pmtiles. # Conflicts: # Gruntfile.js
1 parent 72c23f5 commit ac6dde9

File tree

3 files changed

+64
-55
lines changed

3 files changed

+64
-55
lines changed

Gruntfile.js

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = function(grunt) {
2+
const rollup = require('rollup');
3+
const rollupConfig = require('./rollup.config.js');
24
const Diff = require('diff');
3-
const nodeResolve = require('@rollup/plugin-node-resolve');
4-
const loadLocalePlugin = require('./load-locales.js');
5-
const alias = require('@rollup/plugin-alias');
65
grunt.initConfig({
76
pkg: grunt.file.readJSON('package.json'),
87
cssmin: {
@@ -12,23 +11,10 @@ module.exports = function(grunt) {
1211
},
1312
combine: {
1413
files: {
15-
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'src/mapml.css']
14+
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'src/mapml.css']
1615
}
1716
}
1817
},
19-
uglify: {
20-
options: {
21-
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
22-
sourceMap: {
23-
includeSources: true
24-
}
25-
},
26-
dist: {
27-
files: {
28-
'dist/mapml.js': ['<%= rollup.main.dest %>']
29-
}
30-
}
31-
},
3218
jshint: {
3319
files: ['Gruntfile.js', 'src/**/*.js','test/**/*.spec.js'],
3420
options: {
@@ -49,7 +35,7 @@ module.exports = function(grunt) {
4935
tasks: ['jshint']
5036
},
5137
copy : {
52-
main : {
38+
main : {
5339
files: [
5440
{
5541
expand: true,
@@ -100,7 +86,7 @@ module.exports = function(grunt) {
10086
expand: true,
10187
src: ['dist/*'],
10288
dest: '../experiments'
103-
}
89+
}
10490
]
10591
},
10692
extension: {
@@ -152,29 +138,7 @@ module.exports = function(grunt) {
152138
src: ['../web-map-doc/dist']
153139
}
154140
},
155-
rollup: {
156-
options: {
157-
format: 'es',
158-
plugins: [
159-
nodeResolve(),
160-
loadLocalePlugin(),
161-
alias({
162-
entries: [
163-
{
164-
find: 'leaflet',
165-
replacement: 'leaflet/dist/leaflet-src.esm.js'
166-
}
167-
]
168-
})
169-
],
170-
external: './pmtilesRules.js'
171-
},
172-
main: {
173-
dest: 'dist/mapmlviewer.js',
174-
src: 'src/mapml/index.js' // Only one source file is permitted
175-
}
176-
},
177-
prettier: {
141+
prettier: {
178142
options: {
179143
// https://prettier.io/docs/en/options.html
180144
progress: true
@@ -188,22 +152,35 @@ module.exports = function(grunt) {
188152
}
189153
});
190154

191-
grunt.loadNpmTasks('grunt-contrib-uglify');
192155
grunt.loadNpmTasks('grunt-contrib-jshint');
193156
grunt.loadNpmTasks('grunt-contrib-watch');
194157
grunt.loadNpmTasks('grunt-contrib-copy');
195158
grunt.loadNpmTasks('grunt-contrib-cssmin');
196159
grunt.loadNpmTasks('grunt-contrib-clean');
197-
grunt.loadNpmTasks('grunt-rollup');
198160
grunt.loadNpmTasks('grunt-prettier');
199161

162+
// "grunt-rollup" plugin seems no longer maintained
163+
grunt.registerTask('customRollup', 'A custom Rollup build task', async function() {
164+
const done = this.async();
165+
try {
166+
// Use the configuration loaded from rollup.config.js
167+
const bundle = await rollup.rollup(rollupConfig);
168+
await bundle.write(rollupConfig.output);
169+
170+
console.log('Rollup build completed successfully.');
171+
done();
172+
} catch (error) {
173+
console.error('Rollup build failed:', error);
174+
done(false);
175+
}
176+
});
200177
grunt.registerTask('format', ['prettier', 'jshint']);
201-
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'rollup',
202-
'uglify', 'cssmin','clean:tidyup']);
203-
grunt.registerTask('experiments',['clean:experiments','default','copy:experiments']);
204-
grunt.registerTask('extension',['clean:extension','default','copy:extension']);
205-
grunt.registerTask('geoserver',['clean:geoserver','default','copy:geoserver']);
206-
grunt.registerTask('docs', ['clean:docs','default','copy:docs']);
207-
grunt.registerTask('sync', ['default','experiments','extension','docs']);
178+
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'customRollup', 'cssmin']);
179+
grunt.registerTask('experiments', ['clean:experiments', 'default', 'copy:experiments']);
180+
grunt.registerTask('extension', ['clean:extension', 'default', 'copy:extension']);
181+
grunt.registerTask('geoserver', ['clean:geoserver', 'default', 'copy:geoserver']);
182+
grunt.registerTask('basemap', ['clean:basemap', 'default', 'copy:basemap']);
183+
grunt.registerTask('docs', ['clean:docs', 'default', 'copy:docs']);
184+
grunt.registerTask('sync', ['default', 'experiments', 'extension', 'docs']);
208185

209186
};

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
}
3333
],
3434
"scripts": {
35-
"postinstall": "npx playwright install --with-deps",
36-
"test": "npx playwright test --retries=3 --workers=1"
35+
"postinstall": "npx playwright install --with-deps",
36+
"test": "npx playwright test --retries=3 --workers=1"
3737
},
3838
"devDependencies": {
3939
"@playwright/test": "^1.39.0",
4040
"@rollup/plugin-alias": "^5.1.1",
4141
"@rollup/plugin-legacy": "^3.0.2",
4242
"@rollup/plugin-node-resolve": "^15.2.3",
43+
"@rollup/plugin-terser": "^0.4.4",
4344
"mapml-extension": "git+https://github.com/Maps4HTML/mapml-extension",
4445
"diff": "^5.1.0",
4546
"express": "^4.17.1",
@@ -49,11 +50,9 @@
4950
"grunt-contrib-copy": "~1.0.0",
5051
"grunt-contrib-cssmin": "^4.0.0",
5152
"grunt-contrib-jshint": "~3.2.0",
52-
"grunt-contrib-uglify": "~5.0.0",
5353
"grunt-contrib-watch": "~1.1.0",
5454
"grunt-html": "^15.2.2",
5555
"grunt-prettier": "^2.2.0",
56-
"grunt-rollup": "^12.0.0",
5756
"leaflet": "^1.9.4",
5857
"leaflet.locatecontrol": "^0.81.1",
5958
"path": "^0.12.7",

rollup.config.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const nodeResolve = require('@rollup/plugin-node-resolve');
2+
const alias = require('@rollup/plugin-alias');
3+
const loadLocalePlugin = require('./load-locales.js');
4+
const terser = require('@rollup/plugin-terser');
5+
6+
module.exports = {
7+
input: 'src/mapml/index.js',
8+
plugins: [
9+
nodeResolve(),
10+
loadLocalePlugin(),
11+
alias({
12+
entries: [
13+
{
14+
find: 'leaflet',
15+
replacement: 'leaflet/dist/leaflet-src.esm.js'
16+
}
17+
]
18+
}),
19+
terser({
20+
compress: true,
21+
mangle: true,
22+
format: {
23+
comments: false
24+
},
25+
sourceMap: true // Maintain source maps even during minification
26+
})
27+
],
28+
output: {
29+
file: 'dist/mapml.js',
30+
format: 'esm',
31+
sourcemap: true
32+
}
33+
};

0 commit comments

Comments
 (0)