From 1d1328cb5d4ae899f8842dd8991136cd83466c32 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Fri, 3 Nov 2023 13:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B0=8F=E7=A8=8B=E5=BA=8Fap?= =?UTF-8?q?p.json=E4=B8=ADtabbar=E7=9A=84iconpath=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/babel-plugin/oakRender.js | 8 +++++++- config/babel-plugin/oakRouter2.js | 4 ++-- plugins/WechatMpPlugin.js | 28 ++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/config/babel-plugin/oakRender.js b/config/babel-plugin/oakRender.js index df4a666..fbe6507 100644 --- a/config/babel-plugin/oakRender.js +++ b/config/babel-plugin/oakRender.js @@ -20,6 +20,12 @@ module.exports = (babel) => { /index\.(ts|js)$/, 'web.js' ); + const xmlFile = filename.replace( + /index\.(ts|js)$/, + 'index.xml' + ); + const xmlFileExists = fs.existsSync(xmlFile); + const tsxFileExists = fs.existsSync(tsxFile); const jsFileExists = fs.existsSync(jsFile); const pcTsxFile = filename.replace( @@ -194,7 +200,7 @@ module.exports = (babel) => { statements.push(...renderJsStatements); } else if (pcJsFileExists) { statements.push(...renderPcJsStatements); - } else { + } else if (!xmlFileExists) { assert( false, `${filename}文件中不存在web.tsx或者web.pc.tsx` diff --git a/config/babel-plugin/oakRouter2.js b/config/babel-plugin/oakRouter2.js index 4dd8178..a755a94 100644 --- a/config/babel-plugin/oakRouter2.js +++ b/config/babel-plugin/oakRouter2.js @@ -107,7 +107,7 @@ function makeRouterItem(page, ns, namespacePath, first) { t.arrowFunctionExpression( [], t.callExpression(t.import(), [ - t.stringLiteral(join('@project', 'pages', ns, path, 'index').replace(/\\/g, '/')) + t.stringLiteral(join(AppPaths.appRootSrc, 'pages', ns, path, 'index').replace(/\\/g, '/')) ]) ), ] @@ -271,7 +271,7 @@ module.exports = () => { t.arrowFunctionExpression( [], t.callExpression(t.import(), [ - t.stringLiteral(join('@project', 'pages', ns, notFound, 'index').replace(/\\/g, '/')) + t.stringLiteral(join(AppPaths.appRootSrc, 'pages', ns, notFound, 'index').replace(/\\/g, '/')) ]) ), ] diff --git a/plugins/WechatMpPlugin.js b/plugins/WechatMpPlugin.js index 7708dae..0494c88 100644 --- a/plugins/WechatMpPlugin.js +++ b/plugins/WechatMpPlugin.js @@ -184,12 +184,15 @@ class OakWeChatMpPlugin { let realPages = []; this.subpackRoot = []; - for (const { iconPath, selectedIconPath } of tabBar.list || []) { + for (const tab of tabBar.list || []) { + const { iconPath, selectedIconPath, pagePath } = tab; if (iconPath) { - tabBarAssets.add(iconPath); + const aliasPath = this.getAliasPath(iconPath); + tabBarAssets.add(aliasPath); } if (selectedIconPath) { - tabBarAssets.add(selectedIconPath); + const aliasPath = this.getAliasPath(selectedIconPath); + tabBarAssets.add(aliasPath); } } @@ -357,7 +360,7 @@ class OakWeChatMpPlugin { ignore: this.getIgnoreExt(), dot: false, }); - + this.assetsEntry = [...entries, ...this.appEntries.tabBarAssets]; this.assetsEntry.forEach((resource) => { new EntryPlugin( @@ -543,6 +546,23 @@ class OakWeChatMpPlugin { appJson.pages = pages; } + if (appJson.tabBar) { + const list = appJson.tabBar.list; + + for (const tab of list || []) { + const { iconPath, selectedIconPath, pagePath } = tab; + if (iconPath) { + tab.iconPath = this.getReplaceAlias(iconPath); + } + if (selectedIconPath) { + tab.selectedIconPath = this.getReplaceAlias(selectedIconPath); + } + if (pagePath) { + tab.pagePath = this.getReplaceAlias(pagePath); + } + } + } + let usingComponents = {}; if (appJson.usingComponents) { for (let ck of Object.keys(appJson.usingComponents)) {