Skip to content

perf(mp): 将子包依赖的静态资源内容打包到子包 assets.js 中#5982

Open
chouchouji wants to merge 1 commit into
uni-app-vue3-devfrom
perf-mp-sub-package-assets-optimize
Open

perf(mp): 将子包依赖的静态资源内容打包到子包 assets.js 中#5982
chouchouji wants to merge 1 commit into
uni-app-vue3-devfrom
perf-mp-sub-package-assets-optimize

Conversation

@chouchouji
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在优化小程序构建产物的分包资源组织方式:将位于子包目录内的静态资源打包到对应子包下的 common/assets.js,以减少主包 common/assets.js 的内容/体积压力。

Changes:

  • 在 Rollup manualChunks 里对静态资源(DEFAULT_ASSETS_RE)按子包根目录进行分桶
  • 静态资源位于子包根目录时,chunk 名称改为 ${subPackageRoot}common/assets,否则仍为 common/assets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 219 to +228
if (DEFAULT_ASSETS_RE.test(filename)) {
debugChunk('common/assets', normalizedId)
const { subPackages } = getSubPackages()
if (subPackages.length) {
const relativePath = normalizePath(path.relative(inputDir, filename))
const subPackageRoot = subPackages.find((subPackage) =>
relativePath.startsWith(subPackage)
)
if (subPackageRoot) {
return subPackageRoot + 'common/assets'
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debugChunk is always called with 'common/assets', but this branch can now return a subpackage-scoped chunk name (e.g. ${subPackageRoot}common/assets). This makes chunk debug output misleading when investigating bundle layout. Consider computing the actual chunk name first, logging that value, and then returning it.

Copilot uses AI. Check for mistakes.
relativePath.startsWith(subPackage)
)
if (subPackageRoot) {
return subPackageRoot + 'common/assets'
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The returned chunk name is built via subPackageRoot + 'common/assets', which implicitly relies on subPackageRoot always ending with / (currently true because getSubPackages() normalizes roots with a trailing slash). To make this more robust against future changes, build the chunk name in a way that guarantees the separator (e.g. a template using the existing trailing slash, or a posix join).

Suggested change
return subPackageRoot + 'common/assets'
return path.posix.join(subPackageRoot, 'common/assets')

Copilot uses AI. Check for mistakes.
relativePath.startsWith(subPackage)
)
if (subPackageRoot) {
return subPackageRoot + 'common/assets'
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior: assets located under a subpackage root are now emitted into a subpackage-specific common/assets chunk. There doesn’t appear to be coverage ensuring the expected output file (e.g. subRoot/common/assets.js) is produced and contains the expected inlined assets. Consider adding/updating an integration test in the playground build tests to cover a project with pages.json subPackages importing an asset within that subpackage.

Suggested change
return subPackageRoot + 'common/assets'
return normalizePath(path.join(subPackageRoot, 'common/assets'))

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

Size report

Path Size
packages/size-check/dist/size-check.es.js 52.77 KB (0%)
packages/size-check/dist/style.css 2.82 KB (0%)
packages/uni-app/dist/uni-app.es.js 2.64 KB (0%)
packages/uni-h5-vue/dist/vue.runtime.esm.js 76.48 KB (0%)
packages/uni-mp-vue/dist/vue.runtime.esm.js 43.74 KB (0%)
packages/uni-mp-alipay/dist/uni.api.esm.js 15.03 KB (0%)
packages/uni-mp-alipay/dist/uni.mp.esm.js 8.19 KB (0%)
packages/uni-mp-baidu/dist/uni.api.esm.js 11.33 KB (0%)
packages/uni-mp-baidu/dist/uni.mp.esm.js 9.68 KB (0%)
packages/uni-mp-qq/dist/uni.api.esm.js 10.65 KB (0%)
packages/uni-mp-qq/dist/uni.mp.esm.js 7.6 KB (0%)
packages/uni-mp-toutiao/dist/uni.api.esm.js 10.59 KB (0%)
packages/uni-mp-toutiao/dist/uni.mp.esm.js 9.42 KB (0%)
packages/uni-mp-weixin/dist/uni.api.esm.js 11.65 KB (0%)
packages/uni-mp-weixin/dist/uni.mp.esm.js 8.16 KB (0%)
packages/uni-quickapp-webview/dist/uni.api.esm.js 10.6 KB (0%)
packages/uni-quickapp-webview/dist/uni.mp.esm.js 8.16 KB (0%)

@chouchouji chouchouji force-pushed the perf-mp-sub-package-assets-optimize branch from a8a3feb to 65fc40e Compare April 9, 2026 06:05
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.

2 participants