fix(mp-vite): 仅被独立分包引用的 npm 打进分包 vendor - #6061
Open
bun-unsafe wants to merge 1 commit into
Open
Conversation
bun-unsafe
force-pushed
the
fix/mp-independent-subpkg-npm-vendor
branch
from
September 3, 2026 19:47
4762029 to
0488861
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import { LibClass } from 'lib'时,uni-mp-vite仍把根目录node_modules打进主包common/vendor.js。独立分包冷启动require('../common/vendor.js')会被微信拒绝(module 'common/vendor.js' is not defined),看起来像e为undefined/LibClass is not a constructor。{root}common/vendor.js。主包或普通分包也引用时,仍走主包 vendor(普通分包可以引用主包,这条本来就是好的)。optimization.subPackages:现有分包优化只处理嵌套的uni_modules/.../node_modules,且那是体积优化;独立分包是运行时正确性。Test plan
packages/uni-mp-vite/__tests__/independentVendorChunk.spec.ts:只被独立分包引用 →{root}common/vendor;普通分包 / 与主包共享 / 两个独立分包共享 → 不搬。{root}common/vendor.js,页面require指向分包 vendor,new LibClass()成功。common/vendor.js。