@modern-js/main-doc 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/_nav.json +1 -1
- package/docs/en/apis/app/commands.mdx +1 -1
- package/docs/en/community/blog/_meta.json +7 -1
- package/docs/en/community/blog/v3-release-note.mdx +625 -0
- package/docs/en/components/rsbuild.mdx +1 -1
- package/docs/en/configure/app/builder-plugins.mdx +1 -1
- package/docs/en/configure/app/dev/server.mdx +7 -7
- package/docs/en/configure/app/resolve/alias-strategy.mdx +1 -1
- package/docs/en/configure/app/resolve/dedupe.mdx +1 -1
- package/docs/en/configure/app/security/sri.mdx +1 -1
- package/docs/en/configure/app/server/rsc.mdx +2 -2
- package/docs/en/configure/app/source/decorators.mdx +1 -1
- package/docs/en/configure/app/tools/bundler-chain.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +1 -1
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/en/guides/basic-features/css/css.mdx +4 -4
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +2 -2
- package/docs/en/guides/basic-features/debug/proxy.mdx +1 -1
- package/docs/en/guides/basic-features/render/rsc.mdx +137 -8
- package/docs/en/guides/concept/builder.mdx +3 -3
- package/docs/en/guides/get-started/tech-stack.mdx +3 -3
- package/docs/en/guides/topic-detail/module-federation/application.mdx +6 -6
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +12 -12
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +1 -1
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +4 -4
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +7 -7
- package/docs/en/guides/troubleshooting/builder.mdx +4 -4
- package/docs/en/guides/upgrade/config.mdx +31 -3
- package/docs/en/plugin/cli-plugins/api.mdx +9 -9
- package/docs/en/plugin/introduction.mdx +5 -5
- package/docs/zh/_nav.json +1 -1
- package/docs/zh/apis/app/commands.mdx +1 -1
- package/docs/zh/community/blog/_meta.json +7 -1
- package/docs/zh/community/blog/v3-release-note.mdx +626 -0
- package/docs/zh/components/rsbuild.mdx +1 -1
- package/docs/zh/configure/app/builder-plugins.mdx +1 -1
- package/docs/zh/configure/app/dev/server.mdx +7 -7
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +1 -1
- package/docs/zh/configure/app/resolve/dedupe.mdx +1 -1
- package/docs/zh/configure/app/security/sri.mdx +1 -1
- package/docs/zh/configure/app/server/rsc.mdx +2 -2
- package/docs/zh/configure/app/source/decorators.mdx +1 -1
- package/docs/zh/configure/app/tools/bundler-chain.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +1 -1
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +1 -1
- package/docs/zh/guides/basic-features/css/css.mdx +4 -4
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +2 -2
- package/docs/zh/guides/basic-features/debug/proxy.mdx +1 -1
- package/docs/zh/guides/basic-features/render/rsc.mdx +222 -8
- package/docs/zh/guides/concept/builder.mdx +3 -3
- package/docs/zh/guides/get-started/tech-stack.mdx +3 -3
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +6 -6
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +12 -12
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +1 -1
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +7 -7
- package/docs/zh/guides/troubleshooting/builder.mdx +4 -4
- package/docs/zh/guides/upgrade/config.mdx +31 -3
- package/docs/zh/plugin/cli-plugins/api.mdx +9 -9
- package/docs/zh/plugin/introduction.mdx +5 -5
- package/package.json +6 -5
- package/rspress.config.ts +1 -2
- package/src/components/Mermaid/index.tsx +3 -0
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/pages/index.tsx +1 -1
|
@@ -38,7 +38,7 @@ Modern.js 提供了 **@modern-js/plugin-i18n** 插件来支持国际化能力。
|
|
|
38
38
|
在 Module Federation 场景下,需要同时安装 i18n 插件和 Module Federation 插件:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
pnpm add i18next react-i18next @modern-js/plugin-i18n @module-federation/modern-js
|
|
41
|
+
pnpm add i18next react-i18next @modern-js/plugin-i18n @module-federation/modern-js-v3
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
:::info
|
|
@@ -54,7 +54,7 @@ pnpm add i18next react-i18next @modern-js/plugin-i18n @module-federation/modern-
|
|
|
54
54
|
```ts title="modern.config.ts"
|
|
55
55
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
56
56
|
import { i18nPlugin } from '@modern-js/plugin-i18n';
|
|
57
|
-
import { moduleFederationPlugin } from '@module-federation/modern-js';
|
|
57
|
+
import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
|
|
58
58
|
|
|
59
59
|
export default defineConfig({
|
|
60
60
|
plugins: [appTools(), i18nPlugin(), moduleFederationPlugin()],
|
|
@@ -84,7 +84,7 @@ export default defineConfig({
|
|
|
84
84
|
#### 配置 Module Federation
|
|
85
85
|
|
|
86
86
|
```ts title="module-federation.config.ts"
|
|
87
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
87
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
88
88
|
|
|
89
89
|
export default createModuleFederationConfig({
|
|
90
90
|
// name 参数必须唯一,不能与其他应用(包括不同的 remote)使用相同的名称
|
|
@@ -199,7 +199,7 @@ export default useSwitchLanguage;
|
|
|
199
199
|
#### 配置 Module Federation
|
|
200
200
|
|
|
201
201
|
```ts title="module-federation.config.ts"
|
|
202
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
202
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
203
203
|
|
|
204
204
|
export default createModuleFederationConfig({
|
|
205
205
|
// name 参数必须唯一,不能与其他应用(包括不同的 remote)使用相同的名称
|
|
@@ -225,7 +225,7 @@ export default createModuleFederationConfig({
|
|
|
225
225
|
首先,在消费者的 `module-federation.config.ts` 中配置远程模块:
|
|
226
226
|
|
|
227
227
|
```ts title="module-federation.config.ts"
|
|
228
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
228
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
229
229
|
|
|
230
230
|
export default createModuleFederationConfig({
|
|
231
231
|
// name 参数必须唯一,不能与其他应用(包括不同的 remote)使用相同的名称
|
|
@@ -254,8 +254,8 @@ export default createModuleFederationConfig({
|
|
|
254
254
|
当生产者使用共享 I18n 实例时,消费者可以直接加载远程组件,无需额外配置:
|
|
255
255
|
|
|
256
256
|
```tsx title="src/routes/page.tsx"
|
|
257
|
-
import { createLazyComponent } from '@module-federation/modern-js/react';
|
|
258
|
-
import { getInstance } from '@module-federation/modern-js/runtime';
|
|
257
|
+
import { createLazyComponent } from '@module-federation/modern-js-v3/react';
|
|
258
|
+
import { getInstance } from '@module-federation/modern-js-v3/runtime';
|
|
259
259
|
|
|
260
260
|
const RemoteComponent = createLazyComponent({
|
|
261
261
|
instance: getInstance(),
|
|
@@ -335,7 +335,7 @@ export default function Layout() {
|
|
|
335
335
|
import '@modern-js/runtime/registry/index';
|
|
336
336
|
import { render } from '@modern-js/runtime/browser';
|
|
337
337
|
import { createRoot } from '@modern-js/runtime/react';
|
|
338
|
-
import { createBridgeComponent } from '@module-federation/modern-js/react-v19';
|
|
338
|
+
import { createBridgeComponent } from '@module-federation/modern-js-v3/react-v19';
|
|
339
339
|
import type { ReactElement } from 'react';
|
|
340
340
|
|
|
341
341
|
const ModernRoot = createRoot();
|
|
@@ -354,7 +354,7 @@ export default provider;
|
|
|
354
354
|
#### 配置 Module Federation
|
|
355
355
|
|
|
356
356
|
```ts title="module-federation.config.ts"
|
|
357
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
357
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
358
358
|
|
|
359
359
|
export default createModuleFederationConfig({
|
|
360
360
|
// name 参数必须唯一,不能与其他应用(包括不同的 remote)使用相同的名称
|
|
@@ -432,7 +432,7 @@ export default defineRuntimeConfig({
|
|
|
432
432
|
首先,在消费者的 `module-federation.config.ts` 中配置远程应用:
|
|
433
433
|
|
|
434
434
|
```ts title="module-federation.config.ts"
|
|
435
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
435
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
436
436
|
|
|
437
437
|
export default createModuleFederationConfig({
|
|
438
438
|
// name 参数必须唯一,不能与其他应用(包括不同的 remote)使用相同的名称
|
|
@@ -460,8 +460,8 @@ export default createModuleFederationConfig({
|
|
|
460
460
|
创建用于加载远程应用的组件:
|
|
461
461
|
|
|
462
462
|
```tsx title="src/components/RemoteApp.tsx"
|
|
463
|
-
import { createRemoteAppComponent } from '@module-federation/modern-js/react';
|
|
464
|
-
import { loadRemote } from '@module-federation/modern-js/runtime';
|
|
463
|
+
import { createRemoteAppComponent } from '@module-federation/modern-js-v3/react';
|
|
464
|
+
import { loadRemote } from '@module-federation/modern-js-v3/runtime';
|
|
465
465
|
import React from 'react';
|
|
466
466
|
|
|
467
467
|
const FallbackErrorComp = (info: any) => {
|
|
@@ -18,7 +18,7 @@ Module Federation 2.0 基于字节跳动内部实践以及 Module Federation 原
|
|
|
18
18
|
|
|
19
19
|
## Modern.js MF 插件
|
|
20
20
|
|
|
21
|
-
基于字节跳动内部实践,Module Federation 团队官方提供了 [Modern.js 插件](https://www.npmjs.com/package/@module-federation/modern-js),帮助开发者更方便的使用 Module Federation。
|
|
21
|
+
基于字节跳动内部实践,Module Federation 团队官方提供了 [Modern.js 插件](https://www.npmjs.com/package/@module-federation/modern-js-v3),帮助开发者更方便的使用 Module Federation。
|
|
22
22
|
|
|
23
23
|
插件会在 Modern.js 应用中注入 Module Federation 插件,并自动处理构建配置、添加运行时代码等。
|
|
24
24
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 服务端渲染
|
|
2
2
|
|
|
3
|
-
`@module-federation/modern-js` 提供了非常强大的能力,开发者可以非常方便的在 Modern.js 应用中,组合使用 Module Federation 和服务端渲染(SSR)的能力。
|
|
3
|
+
`@module-federation/modern-js-v3` 提供了非常强大的能力,开发者可以非常方便的在 Modern.js 应用中,组合使用 Module Federation 和服务端渲染(SSR)的能力。
|
|
4
4
|
|
|
5
5
|
## 开启 SSR
|
|
6
6
|
|
|
@@ -35,7 +35,7 @@ Module Federation 在新版本中支持了[数据获取](https://module-federati
|
|
|
35
35
|
在 Modern.js 中,数据获取可以配合 SSR 使用。我们以前面章节的 Demo 为例子,创建一个数据获取文件:
|
|
36
36
|
|
|
37
37
|
```ts title="src/components/Button.data.ts"
|
|
38
|
-
import type { DataFetchParams } from '@module-federation/modern-js/react';
|
|
38
|
+
import type { DataFetchParams } from '@module-federation/modern-js-v3/react';
|
|
39
39
|
|
|
40
40
|
export type Data = {
|
|
41
41
|
data: string;
|
|
@@ -74,11 +74,11 @@ export const Button = (props: { mfData: Data }) => {
|
|
|
74
74
|
|
|
75
75
|
```tsx title="src/routes/page.tsx"
|
|
76
76
|
import type { JSX } from 'react';
|
|
77
|
-
import { getInstance } from '@module-federation/modern-js/runtime';
|
|
77
|
+
import { getInstance } from '@module-federation/modern-js-v3/runtime';
|
|
78
78
|
import {
|
|
79
79
|
ERROR_TYPE,
|
|
80
80
|
lazyLoadComponentPlugin,
|
|
81
|
-
} from '@module-federation/modern-js/react';
|
|
81
|
+
} from '@module-federation/modern-js-v3/react';
|
|
82
82
|
|
|
83
83
|
const instance = getInstance();
|
|
84
84
|
instance!.registerPlugins([lazyLoadComponentPlugin()]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 开始使用
|
|
2
2
|
|
|
3
|
-
在 Modern.js 中使用 Module Federation 我们推荐使用官方插件 `@module-federation/modern-js`。
|
|
3
|
+
在 Modern.js 中使用 Module Federation 我们推荐使用官方插件 `@module-federation/modern-js-v3`。
|
|
4
4
|
|
|
5
5
|
本章节将会介绍如何通过官方插件搭含生产者应用与消费者应用,我们首先根据 [Modern.js 快速上手](/guides/get-started/quick-start) 创建两个应用。
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { PackageManagerTabs } from '@theme';
|
|
12
12
|
|
|
13
|
-
<PackageManagerTabs command="add @module-federation/modern-js" />
|
|
13
|
+
<PackageManagerTabs command="add @module-federation/modern-js-v3" />
|
|
14
14
|
|
|
15
15
|
## 注册插件
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ import { PackageManagerTabs } from '@theme';
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
21
|
-
import { moduleFederationPlugin } from '@module-federation/modern-js';
|
|
21
|
+
import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
|
|
22
22
|
|
|
23
23
|
export default defineConfig({
|
|
24
24
|
plugins: [appTools(), moduleFederationPlugin()],
|
|
@@ -42,7 +42,7 @@ export const Button = () => {
|
|
|
42
42
|
随后,在项目根目录添加 `module-federation.config.ts`,配置 Module Federation 模块的名称、共享依赖和导出内容:
|
|
43
43
|
|
|
44
44
|
```ts title="module-federation.config.ts"
|
|
45
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
45
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
46
46
|
|
|
47
47
|
export default createModuleFederationConfig({
|
|
48
48
|
name: 'remote',
|
|
@@ -68,7 +68,7 @@ export default createModuleFederationConfig({
|
|
|
68
68
|
|
|
69
69
|
```ts title="modern.config.ts"
|
|
70
70
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
71
|
-
import { moduleFederationPlugin } from '@module-federation/modern-js';
|
|
71
|
+
import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
|
|
72
72
|
|
|
73
73
|
export default defineConfig({
|
|
74
74
|
server: {
|
|
@@ -85,7 +85,7 @@ export default defineConfig({
|
|
|
85
85
|
在项目根目录添加 `module-federation.config.ts`,配置 Module Federation 模块的名称、共享依赖和使用的远程模块:
|
|
86
86
|
|
|
87
87
|
```ts title="module-federation.config.ts"
|
|
88
|
-
import { createModuleFederationConfig } from '@module-federation/modern-js';
|
|
88
|
+
import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
|
|
89
89
|
|
|
90
90
|
export default createModuleFederationConfig({
|
|
91
91
|
name: 'host',
|
|
@@ -170,7 +170,7 @@ export default Index;
|
|
|
170
170
|
|
|
171
171
|
```ts
|
|
172
172
|
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
173
|
-
import { moduleFederationPlugin } from '@module-federation/modern-js';
|
|
173
|
+
import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
|
|
174
174
|
|
|
175
175
|
// https://modernjs.dev/en/configure/app/usage
|
|
176
176
|
export default defineConfig({
|
|
@@ -10,11 +10,11 @@ sidebar_position: 3
|
|
|
10
10
|
|
|
11
11
|
### Rsbuild FAQ
|
|
12
12
|
|
|
13
|
-
Modern.js 内部基于 [Rsbuild](https://rsbuild.
|
|
13
|
+
Modern.js 内部基于 [Rsbuild](https://v2.rsbuild.dev/) 封装了自身的构建工具,因此你可以直接参考 Rsbuild 的 FAQ 文档:
|
|
14
14
|
|
|
15
|
-
- [Rsbuild - 功能类问题](https://rsbuild.
|
|
16
|
-
- [Rsbuild - 异常类问题](https://rsbuild.
|
|
17
|
-
- [Rsbuild - 热更新问题](https://rsbuild.
|
|
15
|
+
- [Rsbuild - 功能类问题](https://v2.rsbuild.dev/zh/guide/faq/features)
|
|
16
|
+
- [Rsbuild - 异常类问题](https://v2.rsbuild.dev/zh/guide/faq/exceptions)
|
|
17
|
+
- [Rsbuild - 热更新问题](https://v2.rsbuild.dev/zh/guide/faq/hmr)
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -151,12 +151,40 @@ export default {
|
|
|
151
151
|
|
|
152
152
|
## tools
|
|
153
153
|
|
|
154
|
+
### toos.postcss
|
|
155
|
+
|
|
156
|
+
**变更内容**:对象式配置会覆盖 Modern.js 内置的 PostCSS 配置。如果需要在内置配置基础上进行扩展,请使用函数式配置。
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// v2
|
|
160
|
+
export default {
|
|
161
|
+
tools: {
|
|
162
|
+
postcss: {
|
|
163
|
+
postcssOptions: {
|
|
164
|
+
plugins: [tailwindcssPlugin],
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// v3
|
|
173
|
+
export default {
|
|
174
|
+
tools: {
|
|
175
|
+
postcss: (opts, { addPlugins }) => {
|
|
176
|
+
addPlugins(tailwindcssPlugin);
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
154
182
|
### tools.esbuild
|
|
155
183
|
|
|
156
184
|
**变更内容**:该配置已废弃,需要手动切换到 esbuild 压缩。
|
|
157
185
|
|
|
158
186
|
```typescript
|
|
159
|
-
// 该配置已废弃,请参考 [切换压缩器](https://rsbuild.
|
|
187
|
+
// 该配置已废弃,请参考 [切换压缩器](https://v2.rsbuild.dev/zh/config/output/minify#%E5%88%87%E6%8D%A2%E5%8E%8B%E7%BC%A9%E5%99%A8) 来手动切换到 esbuild 压缩
|
|
160
188
|
// tools: {
|
|
161
189
|
// esbuild: { /* 配置 */ }
|
|
162
190
|
// },
|
|
@@ -167,7 +195,7 @@ export default {
|
|
|
167
195
|
**变更内容**:该配置已废弃,需要手动切换到 Terser 压缩。
|
|
168
196
|
|
|
169
197
|
```typescript
|
|
170
|
-
// 该配置已废弃,请参考 [切换压缩器](https://rsbuild.
|
|
198
|
+
// 该配置已废弃,请参考 [切换压缩器](https://v2.rsbuild.dev/zh/config/output/minify#%E5%88%87%E6%8D%A2%E5%8E%8B%E7%BC%A9%E5%99%A8) 来手动切换到 Terser 压缩
|
|
171
199
|
// tools: {
|
|
172
200
|
// terser: { /* 配置 */ }
|
|
173
201
|
// },
|
|
@@ -893,7 +921,7 @@ export default defineRuntimeConfig({
|
|
|
893
921
|
|
|
894
922
|
### performance.bundleAnalyze
|
|
895
923
|
|
|
896
|
-
**变更内容**:该配置已废弃,建议使用 [Rsdoctor](https://rsbuild.
|
|
924
|
+
**变更内容**:该配置已废弃,建议使用 [Rsdoctor](https://v2.rsbuild.dev/zh/guide/debug/rsdoctor) 来分析产物体积
|
|
897
925
|
|
|
898
926
|
### performance.transformLodash
|
|
899
927
|
|
|
@@ -188,7 +188,7 @@ api.config(() => {
|
|
|
188
188
|
- **参数:**
|
|
189
189
|
- `modifyFn`: 修改函数,接收 `RspackChain` 实例和实用工具作为参数。
|
|
190
190
|
- **执行阶段:** 在生成最终的 Rspack 配置时。
|
|
191
|
-
- **对应 Rsbuild Hook**: [modifybundlerchain](https://rsbuild.
|
|
191
|
+
- **对应 Rsbuild Hook**: [modifybundlerchain](https://v2.rsbuild.dev/zh/plugins/dev/hooks#modifybundlerchain)
|
|
192
192
|
- **示例:**
|
|
193
193
|
|
|
194
194
|
```typescript
|
|
@@ -208,7 +208,7 @@ api.modifyBundlerChain((chain, utils) => {
|
|
|
208
208
|
- **参数:**
|
|
209
209
|
- `modifyFn`: 修改函数,接收 Rsbuild 配置对象和实用工具作为参数,可以返回修改后的配置对象、Promise 或不返回(直接修改原对象)。
|
|
210
210
|
- **执行阶段:** 在生成最终的 Rsbuild 配置时。
|
|
211
|
-
- **对应 Rsbuild Hook**: [modifyRsbuildConfig](https://rsbuild.
|
|
211
|
+
- **对应 Rsbuild Hook**: [modifyRsbuildConfig](https://v2.rsbuild.dev/zh/plugins/dev/hooks#modifyrsbuildconfig)
|
|
212
212
|
- **示例:**
|
|
213
213
|
|
|
214
214
|
```typescript
|
|
@@ -228,7 +228,7 @@ api.modifyRsbuildConfig((config, utils) => {
|
|
|
228
228
|
- **参数:**
|
|
229
229
|
- `modifyFn`: 修改函数,接收 Rspack 配置对象和实用工具作为参数,可以返回修改后的配置对象、Promise 或不返回(直接修改原对象)。
|
|
230
230
|
- **执行阶段:** 在生成最终的 Rspack 配置时。
|
|
231
|
-
- **对应 Rsbuild Hook**: [modifyRspackConfig](https://rsbuild.
|
|
231
|
+
- **对应 Rsbuild Hook**: [modifyRspackConfig](https://v2.rsbuild.dev/zh/plugins/dev/hooks#modifyrspackconfig)
|
|
232
232
|
- **示例:**
|
|
233
233
|
|
|
234
234
|
```typescript
|
|
@@ -403,7 +403,7 @@ api.onFileChanged(({ filename, eventType }) => {
|
|
|
403
403
|
- **参数:**
|
|
404
404
|
- `buildFn`: 构建前执行的函数,无参数,可异步。
|
|
405
405
|
- **执行阶段:** 在执行构建流程之前。
|
|
406
|
-
- **对应 Rsbuild Hook**: [onBeforeBuild](https://rsbuild.
|
|
406
|
+
- **对应 Rsbuild Hook**: [onBeforeBuild](https://v2.rsbuild.dev/zh/plugins/dev/hooks#onbeforebuild)
|
|
407
407
|
- **示例:**
|
|
408
408
|
|
|
409
409
|
```typescript
|
|
@@ -422,7 +422,7 @@ api.onBeforeBuild(() => {
|
|
|
422
422
|
- **参数:**
|
|
423
423
|
- `buildFn`: 构建后执行的函数,无参数,可异步。
|
|
424
424
|
- **执行阶段:** 在执行构建流程之后。
|
|
425
|
-
- **对应 Rsbuild Hook**: [onAfterBuild](https://rsbuild.
|
|
425
|
+
- **对应 Rsbuild Hook**: [onAfterBuild](https://v2.rsbuild.dev/zh/plugins/dev/hooks#onafterbuild)
|
|
426
426
|
- **示例:**
|
|
427
427
|
|
|
428
428
|
```typescript
|
|
@@ -441,7 +441,7 @@ api.onAfterBuild(() => {
|
|
|
441
441
|
- **参数:**
|
|
442
442
|
- `compileFn`: 编译完成后执行的函数。
|
|
443
443
|
- **执行阶段:** 开发服务器启动,且首次编译完成后。
|
|
444
|
-
- **对应 Rsbuild Hook**: [onDevCompileDone](https://rsbuild.
|
|
444
|
+
- **对应 Rsbuild Hook**: [onDevCompileDone](https://v2.rsbuild.dev/zh/plugins/dev/hooks#ondevcompiledone)
|
|
445
445
|
- **示例:**
|
|
446
446
|
|
|
447
447
|
```typescript
|
|
@@ -460,7 +460,7 @@ api.onDevCompileDone(() => {
|
|
|
460
460
|
- **参数:**
|
|
461
461
|
- `createFn`: 创建前执行的函数,无参数,可异步。
|
|
462
462
|
- **执行阶段:** 在创建 Rspack 编译器实例之前。
|
|
463
|
-
- **对应 Rsbuild Hook**: [onBeforeCreateCompiler](https://rsbuild.
|
|
463
|
+
- **对应 Rsbuild Hook**: [onBeforeCreateCompiler](https://v2.rsbuild.dev/zh/plugins/dev/hooks#onbeforecreatecompiler)
|
|
464
464
|
- **示例:**
|
|
465
465
|
|
|
466
466
|
```typescript
|
|
@@ -479,7 +479,7 @@ api.onBeforeCreateCompiler(() => {
|
|
|
479
479
|
- **参数:**
|
|
480
480
|
- `createFn`: 创建后执行的函数,无参数,可异步。
|
|
481
481
|
- **执行阶段:** 在创建 Rspack 编译器实例之后。
|
|
482
|
-
- **对应 Rsbuild Hook**: [onAfterCreateCompiler](https://rsbuild.
|
|
482
|
+
- **对应 Rsbuild Hook**: [onAfterCreateCompiler](https://v2.rsbuild.dev/zh/plugins/dev/hooks#onaftercreatecompiler)
|
|
483
483
|
- **示例:**
|
|
484
484
|
|
|
485
485
|
```typescript
|
|
@@ -517,7 +517,7 @@ api.onBeforeDev(async () => {
|
|
|
517
517
|
- **参数:**
|
|
518
518
|
- `devFn`: 开发服务器启动后执行的函数。
|
|
519
519
|
- **执行阶段:** 开发服务器成功启动后。
|
|
520
|
-
- **对应 Rsbuild Hook**: [onAfterStartDevServer](https://rsbuild.
|
|
520
|
+
- **对应 Rsbuild Hook**: [onAfterStartDevServer](https://v2.rsbuild.dev/zh/plugins/dev/hooks#onafterstartdevserver)
|
|
521
521
|
- **示例:**
|
|
522
522
|
|
|
523
523
|
```typescript
|
|
@@ -117,7 +117,7 @@ Rsbuild 是 Modern.js 底层的构建工具,通过添加 Rsbuild 插件可修
|
|
|
117
117
|
你可以在 `modern.config.ts` 中通过 `builderPlugins` 选项注册 Rsbuild 插件,详见 [builderPlugins 构建插件](/configure/app/builder-plugins.html)。
|
|
118
118
|
|
|
119
119
|
:::info
|
|
120
|
-
可以阅读 [Rsbuild 官网 - 插件](https://rsbuild.
|
|
120
|
+
可以阅读 [Rsbuild 官网 - 插件](https://v2.rsbuild.dev/plugins/list/index) 了解更多 Rsbuild 插件体系内容。
|
|
121
121
|
:::
|
|
122
122
|
|
|
123
123
|
### 官方插件
|
|
@@ -128,9 +128,9 @@ Rsbuild 是 Modern.js 底层的构建工具,通过添加 Rsbuild 插件可修
|
|
|
128
128
|
|
|
129
129
|
| 插件 | 介绍 | Modern.js 链接 |
|
|
130
130
|
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
-
| [React 插件](https://rsbuild.
|
|
132
|
-
| [SVGR 插件](https://rsbuild.
|
|
133
|
-
| [Assets Retry 插件](https://
|
|
131
|
+
| [React 插件](https://v2.rsbuild.dev/zh/plugins/list/plugin-react) | 提供对 React 的支持 | - |
|
|
132
|
+
| [SVGR 插件](https://v2.rsbuild.dev/zh/plugins/list/plugin-svgr) | 支持将 SVG 图片转换为一个 React 组件 | [output.disableSvgr](/configure/app/output/disable-svgr)<br />[output.svgDefaultExport](/configure/app/output/svg-default-export) |
|
|
133
|
+
| [Assets Retry 插件](https://github.com/rstackjs/rsbuild-plugin-assets-retry) | 用于在静态资源加载失败时自动发起重试请求 | [output.assetsRetry](/configure/app/output/assets-retry.html) |
|
|
134
134
|
| [Type Check 插件](https://github.com/rspack-contrib/rsbuild-plugin-type-check) | 用于在单独的进程中运行 TypeScript 类型检查 | [output.disableTsChecker](/configure/app/output/disable-ts-checker.html)<br />[tools.tsChecker](/configure/app/tools/ts-checker.html) |
|
|
135
135
|
| [Source Build 插件](https://github.com/rspack-contrib/rsbuild-plugin-source-build) | 用于 monorepo 场景,支持引用其他子目录的源代码,并完成构建和热更新 | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
|
|
136
136
|
| [Check Syntax 插件](https://github.com/rspack-contrib/rsbuild-plugin-check-syntax) | 用于分析产物的语法兼容性,判断是否存在导致兼容性问题的高级语法 | [security.checkSyntax](/configure/app/security/check-syntax.html) |
|
|
@@ -142,7 +142,7 @@ Rsbuild 是 Modern.js 底层的构建工具,通过添加 Rsbuild 插件可修
|
|
|
142
142
|
以下是未在 Modern.js 中内置的 Rsbuild 官方插件:
|
|
143
143
|
|
|
144
144
|
- [Image Compress 插件](https://github.com/rspack-contrib/rsbuild-plugin-image-compress):将项目中用到的图片资源进行压缩处理。
|
|
145
|
-
- [Stylus 插件](https://rsbuild.
|
|
145
|
+
- [Stylus 插件](https://v2.rsbuild.dev/zh/plugins/list/plugin-stylus):使用 Stylus 作为 CSS 预处理器。
|
|
146
146
|
- [UMD 插件](https://github.com/rspack-contrib/rsbuild-plugin-umd):用于构建 UMD 格式的产物。
|
|
147
147
|
- [YAML 插件](https://github.com/rspack-contrib/rsbuild-plugin-yaml):用于引用 YAML 文件,并将其转换为 JavaScript 对象。
|
|
148
148
|
- [TOML 插件](https://github.com/rspack-contrib/rsbuild-plugin-toml):用于引用 TOML 文件,并将其转换为 JavaScript 对象。
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/main-doc",
|
|
3
3
|
"description": "Documentation of modern.js framework",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"homepage": "https://modernjs.dev",
|
|
5
6
|
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
7
|
"repository": {
|
|
@@ -15,20 +16,20 @@
|
|
|
15
16
|
"modern",
|
|
16
17
|
"modern.js"
|
|
17
18
|
],
|
|
18
|
-
"version": "3.0.
|
|
19
|
+
"version": "3.0.2",
|
|
19
20
|
"publishConfig": {
|
|
20
21
|
"registry": "https://registry.npmjs.org/",
|
|
21
22
|
"access": "public"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"mermaid": "^11.12.2",
|
|
25
|
-
"@modern-js/sandpack-react": "3.0.
|
|
26
|
+
"@modern-js/sandpack-react": "3.0.2"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@rsbuild/plugin-sass": "1.5.0",
|
|
29
|
-
"@rspress/core": "2.0.
|
|
30
|
-
"@rspress/plugin-llms": "2.0.
|
|
31
|
-
"@rspress/shared": "2.0.
|
|
30
|
+
"@rspress/core": "2.0.2",
|
|
31
|
+
"@rspress/plugin-llms": "2.0.2",
|
|
32
|
+
"@rspress/shared": "2.0.2",
|
|
32
33
|
"@shikijs/transformers": "^3.21.0",
|
|
33
34
|
"@types/fs-extra": "9.0.13",
|
|
34
35
|
"@types/node": "^20",
|
package/rspress.config.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { pluginSass } from '@rsbuild/plugin-sass';
|
|
3
3
|
import { defineConfig } from '@rspress/core';
|
|
4
|
-
import { pluginLlms } from '@rspress/plugin-llms';
|
|
5
4
|
import { transformerNotationHighlight } from '@shikijs/transformers';
|
|
6
5
|
|
|
7
6
|
const docPath = path.join(__dirname, 'docs');
|
|
8
7
|
|
|
9
8
|
export default defineConfig({
|
|
10
9
|
root: docPath,
|
|
10
|
+
llms: true,
|
|
11
11
|
title: 'Modern.js',
|
|
12
12
|
description:
|
|
13
13
|
'The Modern.js framework is a progressive web framework based on React. At ByteDance, we use Modern.js to build upper-level frameworks that have supported the development of thousands of web applications.',
|
|
@@ -22,7 +22,6 @@ export default defineConfig({
|
|
|
22
22
|
transformers: [transformerNotationHighlight()],
|
|
23
23
|
},
|
|
24
24
|
},
|
|
25
|
-
plugins: [pluginLlms()],
|
|
26
25
|
search: {
|
|
27
26
|
codeBlocks: true,
|
|
28
27
|
},
|
|
@@ -20,6 +20,9 @@ export default function Mermaid({
|
|
|
20
20
|
const [renderError, setRenderError] = useState(false);
|
|
21
21
|
|
|
22
22
|
async function renderMermaid2SVG() {
|
|
23
|
+
if (typeof document === 'undefined') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
23
26
|
// https://github.com/mermaid-js/mermaid/blob/1b40f552b20df4ab99a986dd58c9d254b3bfd7bc/packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue#L53
|
|
24
27
|
const hasDarkClass = document.documentElement.classList.contains('dark');
|
|
25
28
|
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
|
|
4
4
|
const RsbuildLink = ({ configName }: { configName: string }) => {
|
|
5
5
|
const lang = useLang();
|
|
6
|
-
const href = `https://v2.rsbuild.
|
|
6
|
+
const href = `https://v2.rsbuild.dev/${lang === 'zh' ? 'zh/' : ''}config/${configName
|
|
7
7
|
.split('.')
|
|
8
8
|
.join('/')
|
|
9
9
|
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
package/src/index.ts
CHANGED
package/src/pages/index.tsx
CHANGED