Comando Line Tool

Module Federation provides a lightweight command-line tool mf, shipped by @module-federation/enhanced.

Note

Once you have completed integration by seguintes an integration guia, @module-federation/enhanced is typically já in your dependência tree and this command is available out of the box. Caso contrário, install it manually in seu projeto before running the commands below.

View All Comandos

If you need to view all available CLI commands, please run the following command in the project directory:

npx mf -h

Output:


Usage: mf <command> [options]

Options:
  -V, --version   output the version number
  -h, --help      display help for command

Commands:
  dts [options]   generate or fetch the mf types
  help [command]  display help for command

Common Opções

Module Federation CLI fornece some comum opções esse pode ser usado for all comandos:

OpçãoDescription
-c, --config <config>Specify the configuration file path, which can be a relative or absolute path. The default value is module-federation.config.ts
-m, --mode <mode>Specify the running environment, you can choose "dev" or "prod". The default value is "dev". After setting, "development" or "production" will be automatically injected into the process.env.NODE_ENV environment variable according to the value.
-h, --helpShow comando help

mf dts

mf dts é usado para pull ou generate tipo TypeScript declaration arquivos.


Usage: mf dts [options]

generate or fetch the mf types

Options:
  --root <root>         specify the project root directory
  --output <output>     specify the generated dts output directory
  --fetch <boolean>     fetch types from remote, default is true (default: true)
  --generate <boolean>  generate types, default is true (default: true)
  -c --config <config>  specify the configuration file, can be a relative or absolute path
  -m --mode <mode>      Specify the runtime environment. You can choose "dev" or "prod". The default value is "dev". After setting, the process.env.NODE_ENV environment variable will be
                        automatically injected with "development" or "production" according to the value. (default: "dev")
  -h, --help            display help for command
注意

The mf dts command will automatically generate or pull type declaration files baseado em the configuração in module-federation.configuração.ts. Isso means you must provide a valid configuração file, caso contrário the command will not run correctly.

If you are only using the runtime API, you need to criar a temporary module-federation.configuração.ts file, configure dts.consumeTypes.remoteTypeUrls, and then run the mf dts command.