diff --git a/packages/core/src/cli/mf.ts b/packages/core/src/cli/mf.ts index b24dde1de..8dad91a3b 100644 --- a/packages/core/src/cli/mf.ts +++ b/packages/core/src/cli/mf.ts @@ -14,11 +14,11 @@ export async function startMFDevServer( } async function initMFRsbuild( - rslibConfig: RslibConfig, + config: RslibConfig, options: Pick = {}, ): Promise { const { environments, environmentWithInfos } = - await composeRsbuildEnvironments(rslibConfig); + await composeRsbuildEnvironments(config); const selectedEnvironmentIds = environmentWithInfos .filter((env) => { @@ -42,13 +42,13 @@ async function initMFRsbuild( const rsbuildInstance = await createRsbuild({ rsbuildConfig: { mode: 'development', - root: rslibConfig.root, - plugins: rslibConfig.plugins, + root: config.root, + plugins: config.plugins, dev: { - ...(rslibConfig.dev ?? {}), + ...(config.dev ?? {}), writeToDisk: true, }, - server: rslibConfig.server, + server: config.server, tools: { rspack: { optimization: { diff --git a/packages/plugin-dts/src/index.ts b/packages/plugin-dts/src/index.ts index 6ec70e5dc..b7fba3def 100644 --- a/packages/plugin-dts/src/index.ts +++ b/packages/plugin-dts/src/index.ts @@ -1,11 +1,7 @@ import { type ChildProcess, fork } from 'node:child_process'; import { dirname, extname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { - type EnvironmentConfig, - type RsbuildPlugin, - logger, -} from '@rsbuild/core'; +import { type RsbuildConfig, type RsbuildPlugin, logger } from '@rsbuild/core'; import ts from 'typescript'; import { loadTsconfig, processSourceEntry } from './utils'; @@ -43,8 +39,8 @@ export type DtsGenOptions = PluginDtsOptions & { tsconfigPath: string; tsConfigResult: ts.ParsedCommandLine; rootDistPath: string; - cleanDistPath: NonNullable['cleanDistPath']; - userExternals?: NonNullable['externals']; + cleanDistPath: NonNullable['cleanDistPath']; + userExternals?: NonNullable['externals']; }; interface TaskResult { diff --git a/packages/plugin-dts/src/utils.ts b/packages/plugin-dts/src/utils.ts index c22729570..ff93bfa25 100644 --- a/packages/plugin-dts/src/utils.ts +++ b/packages/plugin-dts/src/utils.ts @@ -2,7 +2,7 @@ import fs from 'node:fs'; import fsP from 'node:fs/promises'; import { platform } from 'node:os'; import path, { basename, dirname, join, relative, resolve } from 'node:path'; -import { type EnvironmentConfig, logger } from '@rsbuild/core'; +import { type RsbuildConfig, logger } from '@rsbuild/core'; import MagicString from 'magic-string'; import color from 'picocolors'; import { convertPathToPattern, glob } from 'tinyglobby'; @@ -167,7 +167,7 @@ export async function processDtsFiles( export function processSourceEntry( bundle: boolean, - entryConfig: NonNullable['entry'], + entryConfig: NonNullable['entry'], ): DtsEntry { if (!bundle) { return { diff --git a/website/docs/en/config/lib/index.mdx b/website/docs/en/config/lib/index.mdx index 48fb0254a..93b6d3b80 100644 --- a/website/docs/en/config/lib/index.mdx +++ b/website/docs/en/config/lib/index.mdx @@ -3,7 +3,7 @@ - **Type:** ```ts -interface LibConfig extends RsbuildConfig { +interface LibConfig extends EnvironmentConfig { format?: Format; bundle?: boolean; autoExtension?: boolean; diff --git a/website/docs/en/guide/advanced/module-federation.mdx b/website/docs/en/guide/advanced/module-federation.mdx index 73d85f23c..5217f177b 100644 --- a/website/docs/en/guide/advanced/module-federation.mdx +++ b/website/docs/en/guide/advanced/module-federation.mdx @@ -94,14 +94,14 @@ However, if you want this Rslib Module to consume other producers at the same ti Rslib support developing Module Federation Rslib project with a host application. -#### 1. Start `rslib mf dev` command of library +#### 1. Start `rslib mf-dev` command of library Adding the `dev` command to the `package.json` file: ```json title="package.json" { "scripts": { - "dev": "rslib mf dev" + "dev": "rslib mf-dev" } } ``` @@ -152,14 +152,14 @@ Then start the host app with `rsbuild dev`. Rslib support developing Module Federation Rslib project with Storybook. -#### 1. Start `rslib mf dev` command of library +#### 1. Start `rslib mf-dev` command of library Adding the `dev` command to the `package.json` file: ```json title="package.json" { "scripts": { - "dev": "rslib mf dev" + "dev": "rslib mf-dev" } } ``` diff --git a/website/docs/en/guide/basic/cli.mdx b/website/docs/en/guide/basic/cli.mdx index 93b681d63..b90506f16 100644 --- a/website/docs/en/guide/basic/cli.mdx +++ b/website/docs/en/guide/basic/cli.mdx @@ -16,14 +16,14 @@ The output is shown below: Usage: rslib [options] Options: - -V, --version output the version number - -h, --help display help for command + -V, --version output the version number + -h, --help display help for command Commands: - build [options] build the library for production - inspect [options] inspect the Rsbuild / Rspack configs of Rslib projects - mf [options] start Rsbuild dev server of Module Federation format - help [command] display help for command + build [options] build the library for production + inspect [options] inspect the Rsbuild / Rspack configs of Rslib projects + mf-dev [options] start Rsbuild dev server of Module Federation format + help [command] display help for command ``` ## rslib build @@ -40,7 +40,7 @@ Options: -r --root specify the project root directory, can be an absolute path or a path relative to cwd --env-mode specify the env mode to load the `.env.[mode]` file --env-dir specify the directory to load `.env` files - --lib build the specified library (may be repeated) + --lib specify the library (repeatable, e.g. --lib esm --lib cjs) -w --watch turn on watch mode, watch for changes and rebuild -h, --help display help for command ``` @@ -149,7 +149,7 @@ Options: -r --root specify the project root directory, can be an absolute path or a path relative to cwd --env-mode specify the env mode to load the `.env.[mode]` file --env-dir specify the directory to load `.env` files - --lib inspect the specified library (may be repeated) + --lib specify the library (repeatable, e.g. --lib esm --lib cjs) --output specify inspect content output path (default: ".rsbuild") --verbose show full function definitions in output -h, --help display help for command @@ -192,9 +192,9 @@ Inspect config succeed, open following files to view the content: - Rspack Config (cjs): /project/dist/.rsbuild/rspack.config.cjs.mjs ``` -## rslib mf dev +## rslib mf-dev -The `rslib mf dev` command is utilized to start Rsbuild dev server for the [Module Federation](/guide/advanced/module-federation) format. +The `rslib mf-dev` command is utilized to start Rsbuild dev server for the [Module Federation](/guide/advanced/module-federation) format. This enables you to develop and debug your mf format module within the host app. @@ -208,6 +208,7 @@ Options: -r --root specify the project root directory, can be an absolute path or a path relative to cwd --env-mode specify the env mode to load the `.env.[mode]` file --env-dir specify the directory to load `.env` files + --lib specify the library (repeatable, e.g. --lib esm --lib cjs) -h, --help display help for command ``` diff --git a/website/docs/zh/config/lib/index.mdx b/website/docs/zh/config/lib/index.mdx index b034987cf..4b2510a75 100644 --- a/website/docs/zh/config/lib/index.mdx +++ b/website/docs/zh/config/lib/index.mdx @@ -1 +1,30 @@ # Lib 配置 + +- **类型:** + +```ts +interface LibConfig extends EnvironmentConfig { + format?: Format; + bundle?: boolean; + autoExtension?: boolean; + autoExternal?: AutoExternal; + redirect?: Redirect; + syntax?: Syntax; + externalHelpers?: boolean; + banner?: BannerAndFooter; + footer?: BannerAndFooter; + shims?: Shims; + dts?: Dts; + umdName?: string; +} + +interface RslibConfig extends RsbuildConfig { + lib: LibConfig[]; +} +``` + +- **默认值:** `undefined` + +- **必选:** `true` + +`lib` 配置是一个对象数组,每个对象代表一组不同的配置。这些配置包括所有 Rsbuild 配置以及 Rslib 特定的配置,可以生成不同格式的产物。 diff --git a/website/docs/zh/guide/advanced/module-federation.mdx b/website/docs/zh/guide/advanced/module-federation.mdx index 04a8db24f..979661411 100644 --- a/website/docs/zh/guide/advanced/module-federation.mdx +++ b/website/docs/zh/guide/advanced/module-federation.mdx @@ -94,14 +94,14 @@ export default defineConfig({ Rslib 支持宿主应用和 Rslib 模块联邦项目同时开发。 -#### 1. 启动库的 `rslib mf dev` 命令 +#### 1. 启动库的 `rslib mf-dev` 命令 添加 `dev` 命令在 `package.json` 文件: ```json title="package.json" { "scripts": { - "dev": "rslib mf dev" + "dev": "rslib mf-dev" } } ``` @@ -151,14 +151,14 @@ export default defineConfig({ Rslib 支持使用 Storybook 开发 Rslib 模块联邦项目。 -#### 1. 启动库的 `rslib mf dev` 命令 +#### 1. 启动库的 `rslib mf-dev` 命令 添加 `dev` 命令在 `package.json` 文件: ```json title="package.json" { "scripts": { - "dev": "rslib mf dev" + "dev": "rslib mf-dev" } } ``` diff --git a/website/docs/zh/guide/basic/cli.mdx b/website/docs/zh/guide/basic/cli.mdx index 34040b08a..bd31387ab 100644 --- a/website/docs/zh/guide/basic/cli.mdx +++ b/website/docs/zh/guide/basic/cli.mdx @@ -22,7 +22,7 @@ Options: Commands: build [options] 构建用于生产环境的产物 inspect [options] 检查 Rslib 项目的 Rsbuild 配置和 Rspack 配置 - mf [options] 为 Module Federation 格式的库启用 Rsbuild 开发服务器。 + mf-dev [options] 为 Module Federation 格式的库启用 Rsbuild 开发服务器。 help [command] 显示命令帮助 ``` @@ -40,7 +40,7 @@ Options: -r --root 指定项目根目录,可以是绝对路径或者相对于 cwd 的路径 --env-mode 指定 env 模式来加载 `.env.[mode]` 文件 --env-dir 指定目录来加载 `.env` 文件 - --lib 仅构建指定的库(可以重复) + --lib 指定库(可重复,例如 --lib esm --lib cjs) -w --watch 开启 watch 模式, 监听文件变更并重新构建 -h, --help 显示命令帮助 ``` @@ -149,8 +149,8 @@ Options: -r --root 指定项目根目录,可以是绝对路径或者相对于 cwd 的路径 --env-mode 指定 env 模式来加载 `.env.[mode]` 文件 --env-dir 指定目录来加载 `.env` 文件 - --lib 检查指定的库(可以重复) - --output 指定检查内容输出路径(默认:".rsbuild") + --lib 指定库(可重复,例如 --lib esm --lib cjs) + --output 指定检查内容输出路径(默认:".rsbuild") --verbose 在输出中显示完整的函数定义 -h, --help 显示命令帮助 ``` @@ -192,9 +192,9 @@ Inspect config succeed, open following files to view the content: - Rspack Config (cjs): /project/dist/.rsbuild/rspack.config.cjs.mjs ``` -## rslib mf dev +## rslib mf-dev -`rslib mf dev` 命令用于为 [Module Federation](/guide/advanced/module-federation) 格式的库启用 Rsbuild 开发服务器。 +`rslib mf-dev` 命令用于为 [Module Federation](/guide/advanced/module-federation) 格式的库启用 Rsbuild 开发服务器。 这允许你在 host 应用中访问和调试 mf 格式的模块。 @@ -208,6 +208,7 @@ Options: -r --root 指定项目根目录,可以是绝对路径或者相对于 cwd 的路径 --env-mode 指定 env 模式来加载 `.env.[mode]` 文件 --env-dir 指定目录来加载 `.env` 文件 + --lib 指定库(可重复,例如 --lib esm --lib cjs) -h, --help 显示命令帮助 ```