From a93bcad2039f57722218eee235c3615e0516f55f Mon Sep 17 00:00:00 2001 From: anotherso1a <1181581742@qq.com> Date: Wed, 27 Sep 2023 18:29:42 +0800 Subject: [PATCH] fix: add mainKey in processJSON --- packages/webpack-plugin/lib/loader.js | 1 - packages/webpack-plugin/lib/web/processJSON.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/webpack-plugin/lib/loader.js b/packages/webpack-plugin/lib/loader.js index f8d023bbe2..9061f21083 100644 --- a/packages/webpack-plugin/lib/loader.js +++ b/packages/webpack-plugin/lib/loader.js @@ -200,7 +200,6 @@ module.exports = function (content) { }, (callback) => { processJSON(parts.json, { - ctorType, loaderContext, pagesMap, componentsMap diff --git a/packages/webpack-plugin/lib/web/processJSON.js b/packages/webpack-plugin/lib/web/processJSON.js index cd46f38400..eaeedd99f8 100644 --- a/packages/webpack-plugin/lib/web/processJSON.js +++ b/packages/webpack-plugin/lib/web/processJSON.js @@ -15,7 +15,6 @@ const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDe const RecordGlobalComponentsDependency = require('../dependencies/RecordGlobalComponentsDependency') module.exports = function (json, { - ctorType, loaderContext, pagesMap, componentsMap @@ -79,6 +78,9 @@ module.exports = function (json, { }) } + const { resourcePath } = parseRequest(loaderContext.resource) + const isApp = !(pagesMap[resourcePath] || componentsMap[resourcePath]) + if (!json) { return callback() } @@ -99,12 +101,16 @@ module.exports = function (json, { } } + if (!isApp) { + rulesRunnerOptions.mainKey = pagesMap[resourcePath] ? 'page' : 'component' + } + const rulesRunner = getRulesRunner(rulesRunnerOptions) if (rulesRunner) { rulesRunner(jsonObj) } - if (ctorType === 'app') { + if (isApp) { // 收集全局组件 Object.assign(mpx.usingComponents, jsonObj.usingComponents) // 在 rulesRunner 运行后保存全局注册组件