feat(cli): hooks.beforeWriteEntry 改为 async

This commit is contained in:
kevinyzheng 2022-11-15 15:09:57 +08:00 committed by roymondchen
parent f824b661bd
commit cc21c47829
2 changed files with 3 additions and 3 deletions

View File

@ -61,7 +61,7 @@ export interface UserConfig {
/** 是否使用import()加载组件 */
dynamicImport?: boolean;
hooks?: {
beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => void;
beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => Promise<Record<string, string>>;
};
onInit?: (app: Core) => ModuleMainFilePath | Promise<ModuleMainFilePath>;
onPrepare?: (app: Core) => void;

View File

@ -6,7 +6,7 @@ import { EntryType } from '../types';
export const prepareEntryFile = async (app: App) => {
const { componentMap = {}, pluginMap = {}, configMap = {}, valueMap = {}, eventMap = {} } = app.moduleMainFilePath;
const { componentFileAffix, dynamicImport, hooks } = app.options;
const contentMap: Record<string, string> = {
let contentMap: Record<string, string> = {
'comp-entry.ts': generateContent(EntryType.COMPONENT, componentMap, componentFileAffix),
'async-comp-entry.ts': generateContent(EntryType.COMPONENT, componentMap, componentFileAffix, dynamicImport),
'plugin-entry.ts': generateContent(EntryType.PLUGIN, pluginMap),
@ -17,7 +17,7 @@ export const prepareEntryFile = async (app: App) => {
};
if (typeof hooks?.beforeWriteEntry === 'function') {
await hooks.beforeWriteEntry(contentMap, app);
contentMap = await hooks.beforeWriteEntry(contentMap, app);
}
Object.keys(contentMap).forEach((fileName: string) => {