Skip to content

Commit e9d9240

Browse files
Add bundle statistics to maplibre-gl-js website (#6270)
* bundle stats * move sentence --------- Co-authored-by: wayofthefuture <[email protected]>
1 parent 4a3a319 commit e9d9240

File tree

4 files changed

+125
-2
lines changed

4 files changed

+125
-2
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@ To create a standalone build, run
165165
npm run build-prod
166166
npm run build-css
167167
```
168-
169168
Once those commands finish, you will have a standalone build at `dist/maplibre-gl.js` and `dist/maplibre-gl.css`
170169

170+
## Analyze your Standalone Build
171+
172+
MapLibre seeks to keep production bundle sizes small. If your changes involve substantial additions or changes to dependencies, the effects on bundle size can be visualized by running
173+
```bash
174+
npm run bundle-stats
175+
```
176+
171177
## Testing changes and Writing Documentation
172178

173179
See [`docs/README.md`](./docs/README.md)

build/rollup_plugins.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import terser from '@rollup/plugin-terser';
77
import strip from '@rollup/plugin-strip';
88
import {type Plugin} from 'rollup';
99
import json from '@rollup/plugin-json';
10+
import {visualizer} from 'rollup-plugin-visualizer';
11+
12+
const {BUNDLE} = process.env;
13+
const stats = BUNDLE === 'stats';
1014

1115
// Common set of plugins/transformations shared across different rollup
1216
// builds (main maplibre bundle, style-spec package, benchmarks bundle)
@@ -44,7 +48,19 @@ export const plugins = (production: boolean): Plugin[] => [
4448
// global keyword handling causes Webpack compatibility issues, so we disabled it:
4549
// https://github.com/mapbox/mapbox-gl-js/pull/6956
4650
ignoreGlobal: true
47-
})
51+
}),
52+
// generate bundle stats in multiple formats (treemap, sunburst, etc...)
53+
...(stats ? (['treemap', 'sunburst', 'flamegraph', 'network'] as const).map(template =>
54+
visualizer({
55+
template: template,
56+
title: `gl-js-${template}`,
57+
filename: `staging/${template}.html`,
58+
gzipSize: true,
59+
brotliSize: true,
60+
sourcemap: true,
61+
open: true
62+
})
63+
) : [])
4864
].filter(Boolean) as Plugin[];
4965

5066
export const watchStagingPlugin: Plugin = {

package-lock.json

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"react-dom": "^19.1.1",
115115
"rollup": "^4.46.2",
116116
"rollup-plugin-sourcemaps2": "^0.5.3",
117+
"rollup-plugin-visualizer": "^6.0.3",
117118
"rw": "^1.3.3",
118119
"semver": "^7.7.2",
119120
"sharp": "^0.34.3",
@@ -147,6 +148,7 @@
147148
"watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css",
148149
"build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts",
149150
"watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch",
151+
"bundle-stats": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,BUNDLE:stats",
150152
"spellcheck": "cspell",
151153
"start-server": "st --no-cache -H localhost --port 9966 .",
152154
"start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material",

0 commit comments

Comments
 (0)