From b1efe2f915d05ae7695d4d6f8a253a04bef75a35 Mon Sep 17 00:00:00 2001 From: caihuanyu Date: Wed, 28 Aug 2019 21:01:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20tabBar=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=20iconPath=20=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #150 --- .../src/build/adapters/alipay/index.ts | 17 +++++++++++++++++ .../remax-cli/src/build/adapters/index.ts | 2 ++ .../src/build/adapters/wechat/index.ts | 18 ++++++++++++++++++ packages/remax-cli/src/build/rollupConfig.ts | 2 +- packages/remax-cli/src/getEntries.ts | 19 +++++++++++++++++-- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/packages/remax-cli/src/build/adapters/alipay/index.ts b/packages/remax-cli/src/build/adapters/alipay/index.ts index 84e3b38e0..088c773d5 100644 --- a/packages/remax-cli/src/build/adapters/alipay/index.ts +++ b/packages/remax-cli/src/build/adapters/alipay/index.ts @@ -38,3 +38,20 @@ export function getNativePropName(prop: string) { return prop; } + +export function getIcons(config: any) { + if (!config.tabBar) { + return []; + } + + const tabs: { icon: string; activeIcon: string }[] = config.tabBar.items; + + if (tabs) { + return tabs.reduce( + (images, tab) => [...images, tab.icon, tab.activeIcon], + [] + ); + } + + return []; +} diff --git a/packages/remax-cli/src/build/adapters/index.ts b/packages/remax-cli/src/build/adapters/index.ts index d7b503d7a..b62a4914c 100644 --- a/packages/remax-cli/src/build/adapters/index.ts +++ b/packages/remax-cli/src/build/adapters/index.ts @@ -18,6 +18,8 @@ export interface Adapter { getNativePropName: (key: string) => string; + getIcons: (config: any) => string[]; + moduleFormat: 'cjs' | 'esm'; } diff --git a/packages/remax-cli/src/build/adapters/wechat/index.ts b/packages/remax-cli/src/build/adapters/wechat/index.ts index 7e48f9d59..7f9876967 100644 --- a/packages/remax-cli/src/build/adapters/wechat/index.ts +++ b/packages/remax-cli/src/build/adapters/wechat/index.ts @@ -44,3 +44,21 @@ export function getNativePropName(prop: string) { return prop; } + +export function getIcons(config: any) { + if (!config.tabBar) { + return []; + } + + const tabs: { iconPath: string; selectedIconPath: string }[] = + config.tabBar.list; + + if (tabs) { + return tabs.reduce( + (images, tab) => [...images, tab.iconPath, tab.selectedIconPath], + [] + ); + } + + return []; +} diff --git a/packages/remax-cli/src/build/rollupConfig.ts b/packages/remax-cli/src/build/rollupConfig.ts index a9b1386b8..e86ebaac7 100644 --- a/packages/remax-cli/src/build/rollupConfig.ts +++ b/packages/remax-cli/src/build/rollupConfig.ts @@ -217,7 +217,7 @@ export default function rollupConfig( } const config: RollupOptions = { - input: [entries.app, ...entries.pages.map(p => p.file)], + input: [entries.app, ...entries.pages.map(p => p.file), ...entries.images], output: { dir: options.output, format: adapter.moduleFormat, diff --git a/packages/remax-cli/src/getEntries.ts b/packages/remax-cli/src/getEntries.ts index 70a20f877..680535d6d 100644 --- a/packages/remax-cli/src/getEntries.ts +++ b/packages/remax-cli/src/getEntries.ts @@ -11,12 +11,17 @@ interface AppConfig { root: string; pages: string[]; }[]; + tabBar?: { + items: { icon: string; activeIcon: string }[]; + list: { iconPath: string; selectedIconPath: string }[]; + }; } interface Entries { pageConfigPath: string[]; app: string; pages: Array<{ path: string; file: string }>; + images: string[]; } function searchFile(file: string, ext?: string) { @@ -38,11 +43,12 @@ function searchFile(file: string, ext?: string) { export default function getEntries( options: RemaxOptions, - adpater: Adapter, + adapter: Adapter, context?: Context ): Entries { let pages: any = []; let subpackages: any = []; + let images: string[] = []; if (!context) { const appConfigPath: string = path.join( @@ -53,9 +59,11 @@ export default function getEntries( if (!fs.existsSync(appConfigPath)) { throw new Error(`${appConfigPath} is not found`); } - const appConfig: AppConfig = readManifest(appConfigPath, adpater.name); + const appConfig: AppConfig = readManifest(appConfigPath, adapter.name); pages = appConfig.pages; subpackages = appConfig.subpackages || []; + images = adapter.getIcons(appConfig); + if (!pages || pages.length === 0) { throw new Error( 'app.config.js `pages` field should not be undefined or empty object' @@ -70,6 +78,7 @@ export default function getEntries( pageConfigPath: [], app: searchFile(path.join(options.cwd, 'src', 'app')), pages: [], + images: [], }; entries.pages = pages.reduce( @@ -99,5 +108,11 @@ export default function getEntries( ); }); + entries.images = images + .filter(i => i) + .reduce((paths, image) => { + return [...paths, path.join(options.cwd, 'src', image)]; + }, []); + return entries; }