Skip to content

engine-toolkit-xr miniprogram build bundles engine-xr + engine-math (~2.5MB dist/miniprogram.js) #349

Description

@cptbtptpbcptdtptp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions