logologo
指南
实践
配置
插件
案例
博客
生态
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
指南
实践
配置
插件
案例
博客
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo

开始

介绍
设置环境
快速上手
功能导航
名词解释
npm 包

基础

运行时

Runtime 接入
Runtime API
Runtime Hooks
Rsbuild Plugin
Rspack 插件
Webpack Plugin
Rspress Plugin
Vite Plugin
Metro
类型提示
命令行工具
样式隔离

数据管理

数据获取
数据缓存
Prefetch

框架

Modern.js
Next.js

部署

使用 Zephyr Cloud 部署

调试

开启调试模式
Chrome Devtool
全局变量

Troubleshooting

概览

运行时

RUNTIME-001
RUNTIME-002
RUNTIME-003
RUNTIME-004
RUNTIME-005
RUNTIME-006
RUNTIME-007
RUNTIME-008
RUNTIME-009

构建

BUILD-001
BUILD-002

类型

概览
TYPE-001
其他
Edit this page on GitHub
Previous Page类型提示
Next Page样式隔离

#命令行工具

Module Federation 提供了轻量的命令行工具:@module-federation/enhanced 和 @module-federation/modern-js 。

#查看所有命令

如果你需要查看所有可用的 CLI 命令,请在项目目录中运行以下命令:

npx mf -h

输出如下:


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

#公共选项

Module Federation CLI 提供了一些公共选项,可以用于所有命令:

选项描述
-c, --config <config>指定配置文件路径,可以为相对路径或绝对路径,默认值为 module-federation.config.ts
-m, --mode <mode>指定运行环境,可以选择 "dev" 或 "prod" ,默认值为 "dev" ,设置后会按照值自动往 process.env.NODE_ENV 环境变量注入 "development" 或 "production"
-h, --help显示命令帮助

#mf dts

mf dts 命令用于拉取或生成 TypeScript 类型声明文件。


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
注意

mf dts 命令会自动根据 module-federation.config.ts 中的配置生成或拉取类型声明文件。 这意味着你必须提供一个有效的配置文件,否则命令将无法正常运行。

如果你是只使用了 runtime API,那么你需要创建一份临时的 module-federation.config.ts 文件,配置 dts.consumeTypes.remoteTypeUrls,然后运行 mf dts 命令。