feat(cli): 指定组件不使用动态加载,dynamicImport为true时有效

This commit is contained in:
roymondchen 2025-04-30 11:40:56 +08:00
parent ed01cfca87
commit 85284e54f5
2 changed files with 6 additions and 2 deletions

View File

@ -84,6 +84,8 @@ export interface UserConfig {
npmConfig?: NpmConfig;
/** 是否使用import()加载组件 */
dynamicImport?: boolean;
/** 指定组件不使用动态加载dynamicImport为true时有效 */
dynamicIgnore?: string[];
hooks?: {
beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => Promise<Record<string, string>>;
};

View File

@ -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<string, string> = {
'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<string, string> = {},
map: Record<string, string> = {},
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}'`);