Skip to content

Commit

Permalink
Remove grunt-rollup grunt plugin, replace with customRollup task,
Browse files Browse the repository at this point in the history
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
  • Loading branch information
prushforth committed Nov 14, 2024
1 parent 72c23f5 commit 93326c0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 55 deletions.
79 changes: 28 additions & 51 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = function(grunt) {
const rollup = require('rollup');
const rollupConfig = require('./rollup.config.js');
const Diff = require('diff');
const nodeResolve = require('@rollup/plugin-node-resolve');
const loadLocalePlugin = require('./load-locales.js');
const alias = require('@rollup/plugin-alias');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cssmin: {
Expand All @@ -12,23 +11,10 @@ module.exports = function(grunt) {
},
combine: {
files: {
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'src/mapml.css']
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'src/mapml.css']
}
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
sourceMap: {
includeSources: true
}
},
dist: {
files: {
'dist/mapml.js': ['<%= rollup.main.dest %>']
}
}
},
jshint: {
files: ['Gruntfile.js', 'src/**/*.js','test/**/*.spec.js'],
options: {
Expand All @@ -49,7 +35,7 @@ module.exports = function(grunt) {
tasks: ['jshint']
},
copy : {
main : {
main : {
files: [
{
expand: true,
Expand Down Expand Up @@ -100,7 +86,7 @@ module.exports = function(grunt) {
expand: true,
src: ['dist/*'],
dest: '../experiments'
}
}
]
},
extension: {
Expand Down Expand Up @@ -152,29 +138,7 @@ module.exports = function(grunt) {
src: ['../web-map-doc/dist']
}
},
rollup: {
options: {
format: 'es',
plugins: [
nodeResolve(),
loadLocalePlugin(),
alias({
entries: [
{
find: 'leaflet',
replacement: 'leaflet/dist/leaflet-src.esm.js'
}
]
})
],
external: './pmtilesRules.js'
},
main: {
dest: 'dist/mapmlviewer.js',
src: 'src/mapml/index.js' // Only one source file is permitted
}
},
prettier: {
prettier: {
options: {
// https://prettier.io/docs/en/options.html
progress: true
Expand All @@ -188,22 +152,35 @@ module.exports = function(grunt) {
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-rollup');
grunt.loadNpmTasks('grunt-prettier');

// "grunt-rollup" plugin seems no longer maintained
grunt.registerTask('customRollup', 'A custom Rollup build task', async function() {
const done = this.async();
try {
// Use the configuration loaded from rollup.config.js
const bundle = await rollup.rollup(rollupConfig);
await bundle.write(rollupConfig.output);

console.log('Rollup build completed successfully.');
done();
} catch (error) {
console.error('Rollup build failed:', error);
done(false);
}
});
grunt.registerTask('format', ['prettier', 'jshint']);
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'rollup',
'uglify', 'cssmin','clean:tidyup']);
grunt.registerTask('experiments',['clean:experiments','default','copy:experiments']);
grunt.registerTask('extension',['clean:extension','default','copy:extension']);
grunt.registerTask('geoserver',['clean:geoserver','default','copy:geoserver']);
grunt.registerTask('docs', ['clean:docs','default','copy:docs']);
grunt.registerTask('sync', ['default','experiments','extension','docs']);
grunt.registerTask('default', ['clean:dist', 'copy:main', 'copy:images', 'format', 'customRollup', 'cssmin']);
grunt.registerTask('experiments', ['clean:experiments', 'default', 'copy:experiments']);
grunt.registerTask('extension', ['clean:extension', 'default', 'copy:extension']);
grunt.registerTask('geoserver', ['clean:geoserver', 'default', 'copy:geoserver']);
grunt.registerTask('basemap', ['clean:basemap', 'default', 'copy:basemap']);
grunt.registerTask('docs', ['clean:docs', 'default', 'copy:docs']);
grunt.registerTask('sync', ['default', 'experiments', 'extension', 'docs']);

};
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
}
],
"scripts": {
"postinstall": "npx playwright install --with-deps",
"test": "npx playwright test --retries=3 --workers=1"
"postinstall": "npx playwright install --with-deps",
"test": "npx playwright test --retries=3 --workers=1"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-legacy": "^3.0.2",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"mapml-extension": "git+https://github.com/Maps4HTML/mapml-extension",
"diff": "^5.1.0",
"express": "^4.17.1",
Expand All @@ -49,11 +50,9 @@
"grunt-contrib-copy": "~1.0.0",
"grunt-contrib-cssmin": "^4.0.0",
"grunt-contrib-jshint": "~3.2.0",
"grunt-contrib-uglify": "~5.0.0",
"grunt-contrib-watch": "~1.1.0",
"grunt-html": "^15.2.2",
"grunt-prettier": "^2.2.0",
"grunt-rollup": "^12.0.0",
"leaflet": "^1.9.4",
"leaflet.locatecontrol": "^0.81.1",
"path": "^0.12.7",
Expand Down
33 changes: 33 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const nodeResolve = require('@rollup/plugin-node-resolve');
const alias = require('@rollup/plugin-alias');
const loadLocalePlugin = require('./load-locales.js');
const terser = require('@rollup/plugin-terser');

module.exports = {
input: 'src/mapml/index.js',
plugins: [
nodeResolve(),
loadLocalePlugin(),
alias({
entries: [
{
find: 'leaflet',
replacement: 'leaflet/dist/leaflet-src.esm.js'
}
]
}),
terser({
compress: true,
mangle: true,
format: {
comments: false
},
sourceMap: true // Maintain source maps even during minification
})
],
output: {
file: 'dist/mapml.js',
format: 'esm',
sourcemap: true
}
};

0 comments on commit 93326c0

Please sign in to comment.