From 664dda943b56033bcc0fc8f9ff387135f4f9433c Mon Sep 17 00:00:00 2001 From: xuegan Date: Thu, 10 Aug 2023 01:59:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E5=B1=80=E9=83=A8?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E5=85=9C=E5=BA=95=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webpack-plugin/lib/json-compiler/default-page.mpx | 3 +++ packages/webpack-plugin/lib/json-compiler/helper.js | 11 ++++++++++- packages/webpack-plugin/lib/json-compiler/index.js | 8 +++----- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 packages/webpack-plugin/lib/json-compiler/default-page.mpx diff --git a/packages/webpack-plugin/lib/json-compiler/default-page.mpx b/packages/webpack-plugin/lib/json-compiler/default-page.mpx new file mode 100644 index 0000000000..c3d015dc4d --- /dev/null +++ b/packages/webpack-plugin/lib/json-compiler/default-page.mpx @@ -0,0 +1,3 @@ + diff --git a/packages/webpack-plugin/lib/json-compiler/helper.js b/packages/webpack-plugin/lib/json-compiler/helper.js index 6a2d2b7ebe..77f8b597a3 100644 --- a/packages/webpack-plugin/lib/json-compiler/helper.js +++ b/packages/webpack-plugin/lib/json-compiler/helper.js @@ -6,6 +6,7 @@ const parseRequest = require('../utils/parse-request') const addQuery = require('../utils/add-query') const loaderUtils = require('loader-utils') const resolve = require('../utils/resolve') +const { RESOLVE_IGNORED_ERR } = require('../utils/const') module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) { const mpx = loaderContext.getMpx() @@ -101,7 +102,15 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom // 增加 page 标识 page = addQuery(page, { isPage: true }) resolve(context, page, loaderContext, (err, resource) => { - if (err) return callback(err) + if (err) { + if (err === RESOLVE_IGNORED_ERR && tarRoot) { + const defaultPage = require.resolve('./default-page.mpx') + `?resourcePath=${context}/${tarRoot}/pages/index.mpx` + resource = defaultPage + aliasPath = '' + } else { + return callback(err) + } + } const { resourcePath, queryObj: { isFirst } } = parseRequest(resource) const ext = path.extname(resourcePath) let outputPath diff --git a/packages/webpack-plugin/lib/json-compiler/index.js b/packages/webpack-plugin/lib/json-compiler/index.js index 445b955d92..3c31fe4d06 100644 --- a/packages/webpack-plugin/lib/json-compiler/index.js +++ b/packages/webpack-plugin/lib/json-compiler/index.js @@ -577,12 +577,10 @@ module.exports = function (content) { for (const root in subPackagesCfg) { const subPackageCfg = subPackagesCfg[root] // 分包不存在 pages,输出 subPackages 字段会报错 - if (subPackageCfg.pages.length) { - if (!json.subPackages) { - json.subPackages = [] - } - json.subPackages.push(subPackageCfg) + if (!json.subPackages) { + json.subPackages = [] } + json.subPackages.push(subPackageCfg) } const processOutput = (output) => { output = processDynamicEntry(output)