Summary
@galacean/engine-toolkit-xr@1.6.0 ships a ~2.5 MB dist/miniprogram.js, roughly 30× larger than it should be (~80 KB). @galacean/engine-xr and its @galacean/engine-math dependency are bundled inline instead of being kept external.
(Originally surfaced in #348 against the old @galacean/engine-toolkit-xr-tool; the problem persists — and is slightly worse — in the current @galacean/engine-toolkit-xr.)
Evidence
| package@version |
dist/miniprogram.js |
inlined top-level symbols |
engine-toolkit-xr-tool@0.0.0-experimental-1.3-xr.4 (correct) |
82 KB |
138 |
engine-toolkit-xr-tool@0.0.0-experimental-1.3-xr.14 |
2155 KB |
3058 |
engine-toolkit-xr@1.6.0 (current latest) |
2529 KB |
6570 |
In the 1.6.0 bundle, @galacean/engine is correctly external (require('@galacean/engine/dist/miniprogram')), but XRManager (engine-xr) and Vector3/Matrix/Quaternion (engine-math) are defined inline.
Root cause
Two defects in the miniprogram build config:
1. rollup.config.mjs — the miniprogram external only lists the /dist/miniprogram variants:
.map((name) => `${name}/dist/miniprogram`)
So any peer import that is not rewritten to /dist/miniprogram is not external → it gets bundled.
2. rollup.miniprogram.plugin.mjs — the redirect regex hard-codes mismatched quotes:
const regStr = [`"@galacean/engine"`, `'@galacean/engine-xr'`].join("|");
@galacean/engine is matched with double quotes, @galacean/engine-xr with single quotes. The transpiled (swc) source uses double quotes for both (from "@galacean/engine-xr"), so the @galacean/engine-xr import is never matched → never redirected, falls through to defect (1), and gets bundled — dragging @galacean/engine-math in with it.
Also worth noting
@galacean/engine-xr@1.6.0 ships no /dist/miniprogram entry (only dist/main.js / dist/module.js). So engine-xr must be externalized at its bare package name, not redirected to /dist/miniprogram (which would require a non-existent path). Only @galacean/engine actually ships a dedicated miniprogram build.
Fix
PR: externalize each peer/dep at both its package name and /dist/miniprogram, and redirect only @galacean/engine. @galacean/engine-xr then stays external as require('@galacean/engine-xr') (a path that exists) instead of being bundled.
Verified with a real rollup + rollup-plugin-modify harness: the original config bundles @galacean/engine-xr inline, the patched config externalizes it, and @galacean/engine stays redirected to its miniprogram build in both.
Suggestion
Add a CI size guard on dist/miniprogram.js (e.g. fail if > ~150 KB) — this regression shipped across many versions undetected because nothing monitors bundle size.
Summary
@galacean/engine-toolkit-xr@1.6.0ships a ~2.5 MBdist/miniprogram.js, roughly 30× larger than it should be (~80 KB).@galacean/engine-xrand its@galacean/engine-mathdependency are bundled inline instead of being kept external.(Originally surfaced in #348 against the old
@galacean/engine-toolkit-xr-tool; the problem persists — and is slightly worse — in the current@galacean/engine-toolkit-xr.)Evidence
dist/miniprogram.jsengine-toolkit-xr-tool@0.0.0-experimental-1.3-xr.4(correct)engine-toolkit-xr-tool@0.0.0-experimental-1.3-xr.14engine-toolkit-xr@1.6.0(currentlatest)In the 1.6.0 bundle,
@galacean/engineis correctly external (require('@galacean/engine/dist/miniprogram')), butXRManager(engine-xr) andVector3/Matrix/Quaternion(engine-math) are defined inline.Root cause
Two defects in the miniprogram build config:
1.
rollup.config.mjs— the miniprogramexternalonly lists the/dist/miniprogramvariants:So any peer import that is not rewritten to
/dist/miniprogramis not external → it gets bundled.2.
rollup.miniprogram.plugin.mjs— the redirect regex hard-codes mismatched quotes:@galacean/engineis matched with double quotes,@galacean/engine-xrwith single quotes. The transpiled (swc) source uses double quotes for both (from "@galacean/engine-xr"), so the@galacean/engine-xrimport is never matched → never redirected, falls through to defect (1), and gets bundled — dragging@galacean/engine-mathin with it.Also worth noting
@galacean/engine-xr@1.6.0ships no/dist/miniprogramentry (onlydist/main.js/dist/module.js). So engine-xr must be externalized at its bare package name, not redirected to/dist/miniprogram(which wouldrequirea non-existent path). Only@galacean/engineactually ships a dedicated miniprogram build.Fix
PR: externalize each peer/dep at both its package name and
/dist/miniprogram, and redirect only@galacean/engine.@galacean/engine-xrthen stays external asrequire('@galacean/engine-xr')(a path that exists) instead of being bundled.Verified with a real
rollup+rollup-plugin-modifyharness: the original config bundles@galacean/engine-xrinline, the patched config externalizes it, and@galacean/enginestays redirected to its miniprogram build in both.Suggestion
Add a CI size guard on
dist/miniprogram.js(e.g. fail if > ~150 KB) — this regression shipped across many versions undetected because nothing monitors bundle size.