mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 02:28:04 +08:00 
			
		
		
		
	feat(cli): 指定组件不使用动态加载,dynamicImport为true时有效
This commit is contained in:
		
							parent
							
								
									ed01cfca87
								
							
						
					
					
						commit
						85284e54f5
					
				@ -84,6 +84,8 @@ export interface UserConfig {
 | 
				
			|||||||
  npmConfig?: NpmConfig;
 | 
					  npmConfig?: NpmConfig;
 | 
				
			||||||
  /** 是否使用import()加载组件 */
 | 
					  /** 是否使用import()加载组件 */
 | 
				
			||||||
  dynamicImport?: boolean;
 | 
					  dynamicImport?: boolean;
 | 
				
			||||||
 | 
					  /** 指定组件不使用动态加载,dynamicImport为true时有效 */
 | 
				
			||||||
 | 
					  dynamicIgnore?: string[];
 | 
				
			||||||
  hooks?: {
 | 
					  hooks?: {
 | 
				
			||||||
    beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => Promise<Record<string, string>>;
 | 
					    beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => Promise<Record<string, string>>;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ import { EntryType } from '../types';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const prepareEntryFile = async (app: App) => {
 | 
					export const prepareEntryFile = async (app: App) => {
 | 
				
			||||||
  const { moduleMainFilePath, options } = app;
 | 
					  const { moduleMainFilePath, options } = app;
 | 
				
			||||||
  const { dynamicImport, hooks, useTs = true } = options;
 | 
					  const { dynamicImport, dynamicIgnore, hooks, useTs = true } = options;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let contentMap: Record<string, string> = {
 | 
					  let contentMap: Record<string, string> = {
 | 
				
			||||||
    'comp-entry': generateContent(
 | 
					    'comp-entry': generateContent(
 | 
				
			||||||
@ -20,6 +20,7 @@ export const prepareEntryFile = async (app: App) => {
 | 
				
			|||||||
      moduleMainFilePath.componentPackage,
 | 
					      moduleMainFilePath.componentPackage,
 | 
				
			||||||
      moduleMainFilePath.componentMap,
 | 
					      moduleMainFilePath.componentMap,
 | 
				
			||||||
      dynamicImport,
 | 
					      dynamicImport,
 | 
				
			||||||
 | 
					      dynamicIgnore,
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    'plugin-entry': generateContent(
 | 
					    'plugin-entry': generateContent(
 | 
				
			||||||
      useTs,
 | 
					      useTs,
 | 
				
			||||||
@ -107,6 +108,7 @@ export const generateContent = (
 | 
				
			|||||||
  packageMap: Record<string, string> = {},
 | 
					  packageMap: Record<string, string> = {},
 | 
				
			||||||
  map: Record<string, string> = {},
 | 
					  map: Record<string, string> = {},
 | 
				
			||||||
  dynamicImport = false,
 | 
					  dynamicImport = false,
 | 
				
			||||||
 | 
					  dynamicIgnore: string[] = [],
 | 
				
			||||||
) => {
 | 
					) => {
 | 
				
			||||||
  const list: string[] = [];
 | 
					  const list: string[] = [];
 | 
				
			||||||
  const importDeclarations: string[] = [];
 | 
					  const importDeclarations: string[] = [];
 | 
				
			||||||
@ -117,7 +119,7 @@ export const generateContent = (
 | 
				
			|||||||
    if ([EntryType.CONFIG, EntryType.EVENT, EntryType.VALUE].includes(type) && packagePath === packageMap[key]) {
 | 
					    if ([EntryType.CONFIG, EntryType.EVENT, EntryType.VALUE].includes(type) && packagePath === packageMap[key]) {
 | 
				
			||||||
      importDeclarations.push(`import { ${type} as ${name} } from '${packageMap[key]}'`);
 | 
					      importDeclarations.push(`import { ${type} as ${name} } from '${packageMap[key]}'`);
 | 
				
			||||||
      list.push(`'${key}': ${name}`);
 | 
					      list.push(`'${key}': ${name}`);
 | 
				
			||||||
    } else if (dynamicImport) {
 | 
					    } else if (dynamicImport && !dynamicIgnore.includes(key)) {
 | 
				
			||||||
      list.push(`'${key}': () => import('${packagePath}')`);
 | 
					      list.push(`'${key}': () => import('${packagePath}')`);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      importDeclarations.push(`import ${name} from '${packagePath}'`);
 | 
					      importDeclarations.push(`import ${name} from '${packagePath}'`);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user