| name | optimize-bundle-size |
| description | Reduce plugin `page load bundle size` and avoid unnecessary increases in `packages/kbn-optimizer/limits.yml`. Use when proactively optimizing bundles, investigating CI page-load overages, or reviewing PRs that change bundle limits. |
| disable-model-invocation | true |
Optimize Bundle Size
Use this workflow to keep limits stable by moving non-critical code out of the entry bundle.
1) Set a baseline
- Reference
docs/extend/ci-metrics.md for metric definitions and limits workflow details.
- Build dist metrics for the target plugin and record current
page load bundle size.
node scripts/build_kibana_platform_plugins --focus <pluginId> --dist --workers 4
cat <pluginDir>/target/public/metrics.json
- If this is a regression investigation, compare plugin limits on branch vs upstream.
git show upstream/main:packages/kbn-optimizer/limits.yml | rg '^\\s{2}<pluginId>:'
rg '^\\s{2}<pluginId>:' packages/kbn-optimizer/limits.yml
2) Identify entry-chunk drivers
- Generate a profile build.
node scripts/build_kibana_platform_plugins --focus <pluginId> --dist --profile --no-cache --workers 4
- Find the entry chunk id and top modules in that chunk.
entry_id=$(jq -r '.chunks[] | select((.names|index("<pluginId>")) != null) | .id' <pluginDir>/target/public/stats.json)
jq -r --argjson cid <pluginDir>/target/public/stats.json | -nr | -40