|
| 1 | +# CLI |
| 2 | + |
| 3 | +`@module-federation/enhanced` and `@module-federation/modern-js` provides a lightweight CLI. |
| 4 | + |
| 5 | +## All commands |
| 6 | + |
| 7 | +To view all available CLI commands, run the following command in the project directory: |
| 8 | + |
| 9 | +```bash |
| 10 | +npx mf -h |
| 11 | +``` |
| 12 | + |
| 13 | +The output is shown below: |
| 14 | + |
| 15 | +```text |
| 16 | +Usage: mf <command> [options] |
| 17 | +
|
| 18 | +Options: |
| 19 | + -V, --version output the version number |
| 20 | + -h, --help display help for command |
| 21 | +
|
| 22 | +Commands: |
| 23 | + dts [options] generate or fetch the mf types |
| 24 | + help [command] display help for command |
| 25 | +``` |
| 26 | + |
| 27 | +## Common flags |
| 28 | + |
| 29 | +Module Federation CLI provides several common flags that can be used with all commands: |
| 30 | + |
| 31 | +| Flag | Description | |
| 32 | +| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 33 | +| `-c, --config <config>` | Specify the configuration file, can be a relative or absolute path, default value is `module-federation.ts` | |
| 34 | +| `-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. | |
| 35 | +| `-h, --help` | Display help for command | |
| 36 | + |
| 37 | +## mf dts |
| 38 | + |
| 39 | +The `mf dts` command is used to generate or fetch remote types. |
| 40 | + |
| 41 | +```bash |
| 42 | +Usage: mf dts [options] |
| 43 | + |
| 44 | +generate or fetch the mf types |
| 45 | + |
| 46 | +Options: |
| 47 | + --root <root> specify the project root directory |
| 48 | + --output <output> specify the generated dts output directory |
| 49 | + --fetch <boolean> fetch types from remote, default is true (default: true) |
| 50 | + --generate <boolean> generate types, default is true (default: true) |
| 51 | + -c --config <config> specify the configuration file, can be a relative or absolute path |
| 52 | + -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 |
| 53 | + automatically injected with "development" or "production" according to the value. (default: "dev") |
| 54 | + -h, --help display help for command |
| 55 | +``` |
| 56 | + |
| 57 | +:::info Note |
| 58 | + |
| 59 | +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. |
| 60 | + |
| 61 | +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. |
| 62 | +If you are only using the runtime API, you need to create a temporary `module-federation.config.ts` file, configure [dts.consumeTypes.remoteTypeUrls](../../configure/dts#remotetypeurls), and then run the `mf dts` command. |
| 63 | + |
| 64 | +::: |
0 commit comments