diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index 0de2014e..98b424f3 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -84,6 +84,8 @@ export interface UserConfig { npmConfig?: NpmConfig; /** 是否使用import()加载组件 */ dynamicImport?: boolean; + /** 指定组件不使用动态加载,dynamicImport为true时有效 */ + dynamicIgnore?: string[]; hooks?: { beforeWriteEntry?: (genContentMap: Record, app: Core) => Promise>; }; diff --git a/packages/cli/src/utils/prepareEntryFile.ts b/packages/cli/src/utils/prepareEntryFile.ts index 8a924829..6c051c9c 100644 --- a/packages/cli/src/utils/prepareEntryFile.ts +++ b/packages/cli/src/utils/prepareEntryFile.ts @@ -5,7 +5,7 @@ import { EntryType } from '../types'; export const prepareEntryFile = async (app: App) => { const { moduleMainFilePath, options } = app; - const { dynamicImport, hooks, useTs = true } = options; + const { dynamicImport, dynamicIgnore, hooks, useTs = true } = options; let contentMap: Record = { 'comp-entry': generateContent( @@ -20,6 +20,7 @@ export const prepareEntryFile = async (app: App) => { moduleMainFilePath.componentPackage, moduleMainFilePath.componentMap, dynamicImport, + dynamicIgnore, ), 'plugin-entry': generateContent( useTs, @@ -107,6 +108,7 @@ export const generateContent = ( packageMap: Record = {}, map: Record = {}, dynamicImport = false, + dynamicIgnore: string[] = [], ) => { const list: string[] = []; const importDeclarations: string[] = []; @@ -117,7 +119,7 @@ export const generateContent = ( if ([EntryType.CONFIG, EntryType.EVENT, EntryType.VALUE].includes(type) && packagePath === packageMap[key]) { importDeclarations.push(`import { ${type} as ${name} } from '${packageMap[key]}'`); list.push(`'${key}': ${name}`); - } else if (dynamicImport) { + } else if (dynamicImport && !dynamicIgnore.includes(key)) { list.push(`'${key}': () => import('${packagePath}')`); } else { importDeclarations.push(`import ${name} from '${packagePath}'`);