From 6fe0bdf76757a04a0c1da6e186067c0ff0d66320 Mon Sep 17 00:00:00 2001 From: hiyuki <674883329@qq.com> Date: Mon, 12 Aug 2024 10:49:02 +0800 Subject: [PATCH] fix tt subpackages async --- packages/webpack-plugin/lib/index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/webpack-plugin/lib/index.js b/packages/webpack-plugin/lib/index.js index e53ddc3dbf..9d8651192b 100644 --- a/packages/webpack-plugin/lib/index.js +++ b/packages/webpack-plugin/lib/index.js @@ -535,6 +535,16 @@ class MpxWebpackPlugin { } } + const checkDynamicEntryInfo = (compilation) => { + for (const packageName in mpx.dynamicEntryInfo) { + const entryMap = mpx.dynamicEntryInfo[packageName] + if (packageName !== 'main' && !entryMap.hasPage) { + // 引用未注册分包的所有资源 + const resources = entryMap.entries.map(info => info.resource).join(',') + compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`)) + } + } + } // 构建分包队列,在finishMake钩子当中最先执行,stage传递-1000 compiler.hooks.finishMake.tapAsync({ name: 'MpxWebpackPlugin', @@ -549,17 +559,10 @@ class MpxWebpackPlugin { } ], (err) => { if (err) return callback(err) - const checkDynamicEntryInfo = () => { - for (const packageName in mpx.dynamicEntryInfo) { - const entryMap = mpx.dynamicEntryInfo[packageName] - if (packageName !== 'main' && !entryMap.hasPage) { - // 引用未注册分包的所有资源 - const resources = entryMap.entries.map(info => info.resource).join(',') - compilation.errors.push(new Error(`资源${resources}通过分包异步声明为${packageName}分包, 但${packageName}分包未注册或不存在相关页面!`)) - } - } + if (mpx.supportRequireAsync && mpx.mode !== 'tt') { + // 字节小程序异步分包中不能包含page,忽略该检查 + checkDynamicEntryInfo(compilation) } - checkDynamicEntryInfo() callback() }) })