fix(build): externalize @galacean peers in miniprogram build instead of bundling#350
Conversation
…of bundling The miniprogram bundle of @galacean/engine-toolkit-xr shipped a ~2.5MB dist/miniprogram.js (vs ~80KB) because @galacean/engine-xr and its @galacean/engine-math dependency were bundled inline instead of kept external. Two issues caused it: - The external list only contained the `<pkg>/dist/miniprogram` variants, so any peer import that was not redirected there fell through to bundling. - The redirect regex hard-coded mismatched quotes (`"@galacean/engine"` vs `'@galacean/engine-xr'`). The transpiled source uses double quotes, so the `@galacean/engine-xr` import was never redirected and got bundled, dragging @galacean/engine-math along with it. Externalize every peer/dep at both its package name and `/dist/miniprogram`, and redirect only @galacean/engine (the sole package that actually ships a miniprogram build). @galacean/engine-xr now stays external at `@galacean/engine-xr`, which is a path that exists, rather than being bundled or redirected to a missing entry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughTwo bugs in the miniprogram Rollup build are fixed. The ChangesMiniprogram bundle externalization fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rollup.config.mjs (1)
153-168: Add a CI size budget gate fordist/miniprogram.js.Given this regression persisted across multiple releases, add a CI check that fails when miniprogram output exceeds a threshold (for example, ~150 KB) so future externalization regressions are caught pre-release.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rollup.config.mjs` around lines 153 - 168, Add a CI size budget gate for the dist/miniprogram.js build output. The rollup configuration generates miniprogram.js but there is no automated check to prevent size regressions. Implement a size check in your CI workflow that runs after the build step and fails the build if dist/miniprogram.js exceeds approximately 150 KB, capturing size violations before they reach release. This can be done through a dedicated size checking tool (such as bundlesize or similar CI plugins) or by adding a post-build script that compares the actual output size against your threshold and exits with an error code if exceeded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rollup.config.mjs`:
- Around line 153-168: Add a CI size budget gate for the dist/miniprogram.js
build output. The rollup configuration generates miniprogram.js but there is no
automated check to prevent size regressions. Implement a size check in your CI
workflow that runs after the build step and fails the build if
dist/miniprogram.js exceeds approximately 150 KB, capturing size violations
before they reach release. This can be done through a dedicated size checking
tool (such as bundlesize or similar CI plugins) or by adding a post-build script
that compares the actual output size against your threshold and exits with an
error code if exceeded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7f8d5abb-2d69-4398-9a53-87b2e04c03d7
📒 Files selected for processing (2)
rollup.config.mjsrollup.miniprogram.plugin.mjs
Fixes #349.
Problem
@galacean/engine-toolkit-xr@1.6.0ships a ~2.5 MBdist/miniprogram.js(vs ~80 KB) because@galacean/engine-xrand its@galacean/engine-mathdependency are bundled inline instead of kept external.Two defects in the miniprogram build config:
rollup.config.mjs— theexternallist only contained the<pkg>/dist/miniprogramvariants, so any peer import that wasn't redirected there fell through to bundling.rollup.miniprogram.plugin.mjs— the redirect regex hard-coded mismatched quotes ("@galacean/engine"double,'@galacean/engine-xr'single). The transpiled source uses double quotes, so the@galacean/engine-xrimport was never redirected → bundled → dragged@galacean/engine-mathin with it.Note:
@galacean/engine-xrships no/dist/miniprogrambuild (onlydist/main.js/dist/module.js), so it must be externalized at its bare name — only@galacean/engineactually has a miniprogram build to redirect to.Change
externalnow lists each peer/dep at both its package name and/dist/miniprogram, so a peer that isn't redirected stays external instead of being bundled.@galacean/engineand is quote-agnostic (matches single or double quotes, anchored by a back-reference so@galacean/enginecan't partially match@galacean/engine-xr).Result:
@galacean/engine→require('@galacean/engine/dist/miniprogram'),@galacean/engine-xr→require('@galacean/engine-xr')(a path that exists), neither bundled.Verification
A full native
pnpm buildwasn't run here, so the fix was verified with a focused harness using the realrollup+rollup-plugin-modifyand the exactexternallists, stubbing the engine packages so only the external-vs-bundled decision is exercised:i.e. the original config bundles
@galacean/engine-xr; the patched config externalizes it torequire('@galacean/engine-xr'), while@galacean/enginestays redirected to its miniprogram build. A native build + a CIdist/miniprogram.jssize guard would be a good follow-up to lock this in.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores