Skip to content

fix(build): externalize @galacean peers in miniprogram build instead of bundling#351

Merged
cptbtptpbcptdtptp merged 1 commit into
dev/2.0from
fix/miniprogram-externalize-engine-xr-2.0
Jun 16, 2026
Merged

fix(build): externalize @galacean peers in miniprogram build instead of bundling#351
cptbtptpbcptdtptp merged 1 commit into
dev/2.0from
fix/miniprogram-externalize-engine-xr-2.0

Conversation

@cptbtptpbcptdtptp

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #349 on the dev/2.0 (2.0) line. Counterpart of #350 (which targets main/1.x).

dev/2.0 carries the identical miniprogram build defect, so the same fix is cherry-picked here: externalize each peer/dep at both its package name and /dist/miniprogram, and redirect only @galacean/engine (quote-agnostic). @galacean/engine-xr then stays external as require('@galacean/engine-xr') instead of being bundled (which inlined ~2MB of engine-xr + engine-math into dist/miniprogram.js).

See #349 / #350 for the full root-cause analysis and the rollup + rollup-plugin-modify verification.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Refined miniprogram Rollup configuration to improve dependency externalization and module redirection accuracy in builds.

…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>
(cherry picked from commit 095ea5b)
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ed771db3-cabb-4a76-b1d9-2f5a10ddddb4

📥 Commits

Reviewing files that changed from the base of the PR and between f1be5d9 and 226be75.

📒 Files selected for processing (2)
  • rollup.config.mjs
  • rollup.miniprogram.plugin.mjs

Walkthrough

Two Rollup build files are updated to fix miniprogram CJS output. rollup.config.mjs now externalizes each dependency at both its raw package name and its /dist/miniprogram path using flatMap. rollup.miniprogram.plugin.mjs narrows the import specifier redirect regex to match only @galacean/engine using a quote-anchored back-reference, preventing partial matches against peer packages like @galacean/engine-xr.

Changes

Miniprogram CJS externalization and specifier redirect fix

Layer / File(s) Summary
Miniprogram plugin: narrowed specifier redirect regex
rollup.miniprogram.plugin.mjs
Replaces the hardcoded regex covering @galacean/engine and @galacean/engine-xr with a quote-anchored back-reference pattern that matches only @galacean/engine, preventing partial matches against peer packages and preserving the original quote character in the rewritten specifier.
Rollup config: dual externalization per dependency
rollup.config.mjs
Switches the miniprogram CJS external array construction from map to flatMap so each dependency/peer is externalized under both its raw package name and its /dist/miniprogram entry; adds comments describing the adapter redirection behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 A bunny once tangled in regex despair,
/dist/miniprogram floating everywhere.
With flatMap and back-refs and quotes held tight,
The engine-xr ghost faded out of sight.
Now every extern finds its proper place,
And miniprogram builds at a bunny's pace! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: externalizing @galacean peers in miniprogram build instead of bundling them, which directly addresses the core issue described in the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/miniprogram-externalize-engine-xr-2.0

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cptbtptpbcptdtptp cptbtptpbcptdtptp merged commit d263e37 into dev/2.0 Jun 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant