@@ -42,14 +42,24 @@ adapterArray.forEach((name) => {
4242 adapterVars [ name ] = register ( name ) ;
4343} ) ;
4444
45- const regStr = [ `"@galacean/engine"` , `'@galacean/engine-xr'` ] . join ( "|" ) ;
45+ // Only `@galacean/engine` ships a dedicated miniprogram build whose specifier must be
46+ // redirected to `<pkg>/dist/miniprogram`; other @galacean peers (e.g. @galacean/engine-xr)
47+ // have no such entry and are externalized at their normal package name (see rollup.config.mjs).
48+ //
49+ // The previous implementation matched `@galacean/engine` with double quotes but
50+ // `@galacean/engine-xr` with single quotes; the transpiled source uses double quotes, so the
51+ // `@galacean/engine-xr` import was never matched, fell through to bundling, and dragged
52+ // @galacean /engine-math in with it — bloating dist/miniprogram.js by ~2MB. Matching either
53+ // quote and redirecting only the package that actually has a miniprogram build avoids both.
54+ const redirectModules = [ "@galacean/engine" ] ;
55+ const moduleAlternation = redirectModules . map ( ( name ) => name . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ) . join ( "|" ) ;
4656
4757export default [
4858 inject ( adapterVars ) ,
4959 modify ( {
50- find : new RegExp ( regStr , "g" ) ,
51- replace : ( match , moduleName ) => {
52- return ` ${ match . substr ( 0 , match . length - 1 ) } /dist/miniprogram"` ;
53- }
60+ // Match the specifier in single OR double quotes, anchored by a back-reference so
61+ // `@galacean/engine` does not partially match `@galacean/engine-xr`.
62+ find : new RegExp ( `(['"])( ${ moduleAlternation } )\\1` , "g" ) ,
63+ replace : ( _match , quote , name ) => ` ${ quote } ${ name } /dist/miniprogram ${ quote } `
5464 } )
5565] ;
0 commit comments