Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/uni-mp-vite/src/plugin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ function createMoveToVendorChunkFn(): GetManualChunk | undefined {
// 处理资源文件
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'
Comment on lines 219 to +228
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.
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.
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.
}
}
return 'common/assets'
}
// 处理项目内的js,ts文件
Expand Down
Loading