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)) {