dts

  • Type: boolean | PluginDtsOptions
  • Required: No
  • Default value: true
  • Usage scenario: used to control Module Federation generation/consumption type behavior

After configuration, the producer will automatically generate a compressed type file @mf-types.zip (default name) during build, and the consumer will automatically pull the type file of remotes and decompress it to @mf-types (default name).

The PluginDtsOptions types are as follows:

interface PluginDtsOptions {
  generateTypes?: boolean | DtsRemoteOptions;
  consumeTypes?: boolean | DtsHostOptions;
  tsConfigPath?: string;
}

generateTypes

  • Type: boolean | DtsRemoteOptions
  • Required: No
  • Default value: true
  • Usage scenario: used to control Module Federation generation type behavior

The DtsRemoteOptions types are as follows:

interface DtsRemoteOptions {
  tsConfigPath?: string;
  typesFolder?: string;
  deleteTypesFolder?: boolean;
  additionalFilesToCompile?: string[];
  compilerInstance?: 'tsc' | 'vue-tsc';
  compileInChildProcess?: boolean;
  generateAPITypes?: boolean;
  extractThirdParty?: boolean;
  extractRemoteTypes?: boolean;
  abortOnError?: boolean;
}

When configuring generateTypes to true, the following configuration will be generated by default:

{
  "generateAPITypes": true,
  "abortOnError": false,
  "extractThirdParty": true,
  "extractRemoteTypes": true,
  "compileInChildProcess": true
}

extractRemoteTypes

  • Type: boolean
  • Required: No
  • Default value: undefined
  • Usage scenario: When the content of the producer exposes has its own remotes module that re-exports itself, then extractRemoteTypes: true can ensure that the consumer can normally obtain the module type of the producer exposes
  • Example: [Nested type re-export](../guide/basic/type-prompt#Nested type re-export)

Whether to extract the type of remotes.

extractThirdParty

  • Type: boolean
  • Required: No
  • Default value: undefined
  • Usage scenario: When the content of the producer exposes contains a module containing antd, and the consumer does not have antd installed, then extractThirdParty: true can ensure that the consumer can normally obtain the module of the producer exposes type
  • Example: [Third-party package type extraction](../guide/basic/type-prompt#Third-party package type extraction)

Whether to extract third-party package types.

generateAPITypes

Whether to generate the loadRemote type in Federation Runtime

compileInChildProcess

  • Type: boolean
  • Required: No
  • Default value: undefined

Whether generate types in child process

abortOnError

  • Type: boolean
  • Required: No
  • Default value: false

Whether to throw an error when a problem is encountered during type generation

tsConfigPath

  • Type: string
  • Required: No
  • Default value: path.join(process.cwd(),'./tsconfig.json')

priority: dts.generateTypes.tsConfigPath > dts.tsConfigPath tsconfig configuration file path

typesFolder

  • Type: string
  • Required: No
  • Default value: '@mf-types'

The name of the generated compression type file. For example, if typesFolder is set to custom, then the name of the generated compression type file is: custom.zip

deleteTypesFolder

  • Type: boolean
  • Required: No -Default: true

Whether to delete the generated type folder

compilerInstance

  • Type: 'tsc' | 'vue-tsc'
  • Required: No
  • Default value: 'tsc'

Example of compiled type

consumeTypes

  • Type: boolean | DtsHostOptions
  • Required: No
  • Default value: true
  • Usage scenario: used to control Module Federation consumption (loading) type behavior

The DtsHostOptions types are as follows:

interface DtsHostOptions {
  typesFolder?: string;
  abortOnError?: boolean;
  remoteTypesFolder?: string;
  deleteTypesFolder?: boolean;
  maxRetries?: number;
  consumeAPITypes?: boolean;
}

When configuring consumeTypes to true, the following configuration will be generated by default:

{
  "abortOnError": false,
  "consumeAPITypes": true
}

consumeAPITypes

Whether to generate the type of runtime loadRemote API

maxRetries

  • Type: number
  • Required: No
  • Default value: 3

Maximum number of retries for failed loading

abortOnError

  • Type: boolean
  • Required: No
  • Default value: false

Whether to throw an error when a problem is encountered during type loading

typesFolder

  • Type: string
  • Required: No
  • Default value: '@mf-types'

Type storage directory after successful loading

deleteTypesFolder

  • Type: boolean
  • Required: No
  • Default value: true

Before loading type files, whether to delete the previously loaded typesFolder directory

remoteTypesFolder

  • Type: string
  • Required: No
  • Default value: '@mf-types'

typesFolder corresponding to remotes directory configuration

tsConfigPath

  • Type: string
  • Required: No
  • Default value: path.join(process.cwd(),'./tsconfig.json')

tsconfig configuration file path