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;
 | 
			
		||||
  /** 是否使用import()加载组件 */
 | 
			
		||||
  dynamicImport?: boolean;
 | 
			
		||||
  /** 指定组件不使用动态加载,dynamicImport为true时有效 */
 | 
			
		||||
  dynamicIgnore?: string[];
 | 
			
		||||
  hooks?: {
 | 
			
		||||
    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) => {
 | 
			
		||||
  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}'`);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user