CLI

@module-federation/enhanced and @module-federation/modern-js provides a lightweight CLI.

All commands

To view all available CLI commands, run the following command in the project directory:

npx mf -h

The output is shown below:

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 flags

Module Federation CLI provides several common flags that can be used with all commands:

Flag Description
-c, --config <config> Specify the configuration file, can be a relative or absolute path, default value is module-federation.ts
-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.
-h, --help Display help for command

mf dts

The mf dts command is used to generate or fetch remote types.

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
Note

The mf dts command will automatically generate or pull type declaration files based on the configuration in module-federation.config.ts. This means you must provide a valid configuration file, otherwise the command will not work properly.

If you only use the runtime API, you need to create a temporary module-federation.config.ts file, write the remote configuration you need to get the type, and then run the mf dts command. If you are only using the runtime API, you need to create a temporary module-federation.config.ts file, configure dts.consumeTypes.remoteTypeUrls, and then run the mf dts command.