Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复 tabBar 配置 iconPath 无效的问题
Browse files Browse the repository at this point in the history
fix #150
  • Loading branch information
Darmody committed Aug 28, 2019
1 parent 0b25e40 commit b1efe2f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/remax-cli/src/build/adapters/alipay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(
(images, tab) => [...images, tab.icon, tab.activeIcon],
[]
);
}

return [];
}
2 changes: 2 additions & 0 deletions packages/remax-cli/src/build/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface Adapter {

getNativePropName: (key: string) => string;

getIcons: (config: any) => string[];

moduleFormat: 'cjs' | 'esm';
}

Expand Down
18 changes: 18 additions & 0 deletions packages/remax-cli/src/build/adapters/wechat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(
(images, tab) => [...images, tab.iconPath, tab.selectedIconPath],
[]
);
}

return [];
}
2 changes: 1 addition & 1 deletion packages/remax-cli/src/build/rollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 17 additions & 2 deletions packages/remax-cli/src/getEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand All @@ -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'
Expand All @@ -70,6 +78,7 @@ export default function getEntries(
pageConfigPath: [],
app: searchFile(path.join(options.cwd, 'src', 'app')),
pages: [],
images: [],
};

entries.pages = pages.reduce(
Expand Down Expand Up @@ -99,5 +108,11 @@ export default function getEntries(
);
});

entries.images = images
.filter(i => i)
.reduce<string[]>((paths, image) => {
return [...paths, path.join(options.cwd, 'src', image)];
}, []);

return entries;
}

0 comments on commit b1efe2f

Please sign in to comment.