From 44e218fbd8398d85a2996c608ecde079b618f118 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 30 Dec 2019 22:22:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(mini-runner):=20=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20tabBar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/MiniPlugin.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts index b8264d235e70..0a96d4058649 100644 --- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts @@ -375,7 +375,7 @@ export default class MiniPlugin { }) } - getTabBarFiles (appConfig) { + getTabBarFiles (compiler: webpack.Compiler,appConfig) { const tabBar = appConfig.tabBar const { buildAdapter } = this.options if (tabBar && typeof tabBar === 'object' && !isEmptyObject(tabBar)) { @@ -390,6 +390,24 @@ export default class MiniPlugin { item[pathConfig] && this.tabBarIcons.add(item[pathConfig]) item[selectedPathConfig] && this.tabBarIcons.add(item[selectedPathConfig]) }) + if (tabBar.custom) { + const customTabBarPath = path.join(this.sourceDir, 'custom-tab-bar') + const customTabBarComponentPath = resolveScriptPath(customTabBarPath) + if (fs.existsSync(customTabBarComponentPath)) { + const customTabBarComponentTemplPath = this.getTemplatePath(customTabBarComponentPath) + const isNative = this.isNativePageOrComponent(customTabBarComponentTemplPath, fs.readFileSync(customTabBarComponentPath).toString()) + if (!this.isWatch) { + printLog(processTypeEnum.COMPILE, '自定义 tabBar', this.getShowPath(customTabBarComponentPath)) + } + const componentObj = { + name: 'custom-tab-bar/index', + path: customTabBarComponentPath, + isNative + } + this.components.add(componentObj) + this.getComponents(compiler, new Set([componentObj]), false) + } + } } } @@ -428,7 +446,7 @@ export default class MiniPlugin { return filePath.replace(this.context, '').replace(/\\/g, '/').replace(/^\//, '') } - getPages () { + getPages (compiler: webpack.Compiler) { const { buildAdapter } = this.options const appEntry = this.appEntry const code = fs.readFileSync(appEntry).toString() @@ -451,7 +469,7 @@ export default class MiniPlugin { printLog(processTypeEnum.COMPILE, '发现入口', this.getShowPath(appEntry)) } this.getSubPackages(configObj) - this.getTabBarFiles(configObj) + this.getTabBarFiles(compiler, configObj) const template = '' taroFileTypeMap[this.appEntry] = { type: PARSE_AST_TYPE.ENTRY, @@ -896,7 +914,7 @@ export default class MiniPlugin { run (compiler: webpack.Compiler) { this.errors = [] if (!this.options.isBuildPlugin) { - this.getPages() + this.getPages(compiler) this.getComponents(compiler, this.pages, true) this.addEntries(compiler) } else {