@modern-js/main-doc 3.9.2 → 3.10.0
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/apis/app/hooks/api/lambda.mdx +2 -1
- package/docs/en/apis/app/hooks/config/html.mdx +1 -0
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/en/apis/app/hooks/config/public.mdx +1 -0
- package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/en/apis/app/hooks/shared.mdx +1 -0
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/en/apis/app/hooks/src/server.mdx +2 -1
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
- package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/en/apis/app/runtime/core/render.mdx +6 -2
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/en/apis/app/runtime/router/router.mdx +9 -6
- package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/en/community/blog/v3-release-note.mdx +36 -27
- package/docs/en/community/contributing-guide.mdx +15 -33
- package/docs/en/components/default-browserslist.mdx +0 -1
- package/docs/en/components/deploy-command.mdx +1 -1
- package/docs/en/components/deploy.mdx +1 -1
- package/docs/en/components/entry-scan-logic.mdx +1 -1
- package/docs/en/components/init-app.mdx +9 -3
- package/docs/en/components/international/custom-instance-code.mdx +0 -1
- package/docs/en/components/micro-runtime-config.mdx +12 -9
- package/docs/en/components/nodeVersion.mdx +2 -2
- package/docs/en/components/rsc-deploy-tip.mdx +0 -1
- package/docs/en/components/ssr-monitor.mdx +1 -1
- package/docs/en/configure/app/bff/cross-project.mdx +2 -2
- package/docs/en/configure/app/bff/prefix.mdx +1 -1
- package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/en/configure/app/dev/start-url.mdx +0 -1
- package/docs/en/configure/app/output/css-modules.mdx +1 -5
- package/docs/en/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/en/configure/app/output/dist-path.mdx +0 -1
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/en/configure/app/output/inline-styles.mdx +1 -2
- package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
- package/docs/en/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/en/configure/app/runtime/plugins.mdx +6 -4
- package/docs/en/configure/app/server/rsc.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +7 -8
- package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/en/configure/app/tools/less.mdx +94 -19
- package/docs/en/configure/app/tools/sass.mdx +87 -18
- package/docs/en/configure/app/tools/svgr.mdx +93 -0
- package/docs/en/configure/app/usage.mdx +1 -5
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
- package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
- package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/en/guides/advanced-features/international/api.mdx +34 -28
- package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
- package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
- package/docs/en/guides/advanced-features/international.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
- package/docs/en/guides/advanced-features/source-build.mdx +1 -1
- package/docs/en/guides/advanced-features/web-server.mdx +3 -3
- package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
- package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
- package/docs/en/guides/basic-features/html.mdx +2 -3
- package/docs/en/guides/basic-features/output-files.mdx +1 -1
- package/docs/en/guides/basic-features/render/overview.mdx +12 -12
- package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
- package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
- package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
- package/docs/en/guides/get-started/introduction.mdx +0 -1
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
- package/docs/en/guides/upgrade/config.mdx +12 -0
- package/docs/en/guides/upgrade/other.mdx +4 -4
- package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/en/guides/upgrade/web-server.md +34 -17
- package/docs/en/index.md +1 -0
- package/docs/en/plugin/cli-plugins/api.mdx +23 -23
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/introduction.mdx +6 -6
- package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/en/plugin/plugin-system.mdx +19 -26
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/server-plugins/api.mdx +11 -14
- package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
- package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/zh/apis/app/hooks/shared.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
- package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/zh/community/blog/v3-release-note.mdx +38 -29
- package/docs/zh/community/contributing-guide.mdx +16 -34
- package/docs/zh/components/default-browserslist.mdx +0 -1
- package/docs/zh/components/deploy-command.mdx +1 -1
- package/docs/zh/components/deploy.mdx +1 -1
- package/docs/zh/components/entry-scan-logic.mdx +1 -1
- package/docs/zh/components/init-app.mdx +9 -3
- package/docs/zh/components/international/custom-instance-code.mdx +0 -1
- package/docs/zh/components/international/install-command.mdx +0 -1
- package/docs/zh/components/micro-runtime-config.mdx +12 -9
- package/docs/zh/components/nodeVersion.mdx +2 -2
- package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
- package/docs/zh/components/ssr-monitor.mdx +1 -1
- package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
- package/docs/zh/configure/app/bff/prefix.mdx +1 -1
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
- package/docs/zh/configure/app/html/favicon.mdx +0 -1
- package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
- package/docs/zh/configure/app/output/css-modules.mdx +1 -5
- package/docs/zh/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
- package/docs/zh/configure/app/output/source-map.mdx +0 -2
- package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/zh/configure/app/output/ssg.mdx +1 -0
- package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
- package/docs/zh/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
- package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
- package/docs/zh/configure/app/server/rsc.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -7
- package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/zh/configure/app/tools/less.mdx +93 -19
- package/docs/zh/configure/app/tools/sass.mdx +87 -16
- package/docs/zh/configure/app/tools/svgr.mdx +93 -0
- package/docs/zh/configure/app/usage.mdx +1 -5
- package/docs/zh/guides/advanced-features/bff.mdx +1 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
- package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
- package/docs/zh/guides/advanced-features/international.mdx +9 -9
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
- package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
- package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
- package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
- package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -3
- package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
- package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
- package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/zh/guides/upgrade/config.mdx +12 -0
- package/docs/zh/guides/upgrade/other.md +4 -11
- package/docs/zh/guides/upgrade/overview.mdx +1 -4
- package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/zh/guides/upgrade/web-server.md +34 -19
- package/docs/zh/index.md +1 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/introduction.mdx +6 -6
- package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/zh/plugin/plugin-system.mdx +19 -26
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/server-plugins/api.mdx +11 -14
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
- package/package.json +11 -13
- package/{rspress.config.ts → rstack.config.mts} +7 -10
- package/src/components/Footer/styles.module.scss +1 -1
- package/src/components/SolutionCards/index.module.scss +3 -1
|
@@ -15,10 +15,10 @@ AI Agent 由此获取与当前框架版本严格匹配的 API、配置与约定
|
|
|
15
15
|
|
|
16
16
|
## AGENTS.md
|
|
17
17
|
|
|
18
|
-
`AGENTS.md` 是给 AI 编码助手的项目指引,告诉它在动手前先阅读随包文档、并遵循 Modern.js
|
|
18
|
+
`AGENTS.md` 是给 AI 编码助手的项目指引,告诉它在动手前先阅读随包文档、并遵循 Modern.js 的约定。
|
|
19
19
|
|
|
20
|
-
- **新建项目**:`npx @modern-js/create`
|
|
21
|
-
- **已有项目**:在项目根运行 `npx @modern-js/create --agents-md-only`
|
|
20
|
+
- **新建项目**:`npx @modern-js/create` 默认生成 `AGENTS.md`,加 `--no-agents-md` 可跳过。
|
|
21
|
+
- **已有项目**:在项目根运行 `npx @modern-js/create --agents-md-only` 生成或更新 `AGENTS.md`,可随时重复运行,你添加的自定义内容会被保留。
|
|
22
22
|
|
|
23
23
|
Modern.js 只维护 `AGENTS.md` 中 `<!-- BEGIN:modernjs-agent-rules -->` 标记内的内容,标记之外你写的内容不会被改动。
|
|
24
24
|
|
|
@@ -35,10 +35,10 @@ llms.txt 是遵循 [llms.txt 规范](https://llmstxt.org/) 的在线文档索引
|
|
|
35
35
|
|
|
36
36
|
Skills 是按需触发的 AI 辅助能力,遵循 [Agent Skills 开放标准](https://github.com/vercel-labs/skills)。用户向 Skills:
|
|
37
37
|
|
|
38
|
-
| Skill
|
|
39
|
-
|
|
40
|
-
| 升级到 v3 | `modernjs-migrate-to-v3`
|
|
41
|
-
| 启用特性
|
|
38
|
+
| Skill | 标识 | 说明 |
|
|
39
|
+
| --------- | ------------------------- | ----------------------------------------------------------------------------------------- |
|
|
40
|
+
| 升级到 v3 | `modernjs-migrate-to-v3` | v2 应用迁移到 v3:安全改写 + 复杂项人工清单 + 迁移报告 |
|
|
41
|
+
| 启用特性 | `modernjs-feature-enable` | 为 v3 应用启用 BFF / SSG / styled-components,并脚手架化 Tailwind CSS / 自定义 Web Server |
|
|
42
42
|
|
|
43
43
|
> Skills 默认不强装、不隐式安装,由你显式安装。RSC、微前端等属于配置或架构决策,不是 `modernjs-feature-enable` 的一键启用项。
|
|
44
44
|
|
|
@@ -22,6 +22,18 @@ server: {
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
### dev.lazyCompilation
|
|
26
|
+
|
|
27
|
+
**变更内容**:开发环境下的默认值变化。纯 CSR 与流式 SSR 应用默认开启按需编译,默认值为 `{ imports: true, entries: false }`;使用 string SSR、RSC 或 SSG 的应用仍默认关闭。该变更只影响开发环境,不影响生产构建产物。
|
|
28
|
+
|
|
29
|
+
**迁移示例**:如需保持 2.0 的行为,可以显式关闭:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
dev: {
|
|
33
|
+
lazyCompilation: false;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
25
37
|
## html
|
|
26
38
|
|
|
27
39
|
### html.appIcon
|
|
@@ -22,10 +22,10 @@ Modern.js 3.0 将项目默认入口名称改为 `index`,默认构建出的 HTM
|
|
|
22
22
|
|
|
23
23
|
Modern.js 3.0 对部分运行时进行了调整,需要更新相关的导入路径。路径映射对照如下:
|
|
24
24
|
|
|
25
|
-
| 旧版路径
|
|
26
|
-
|
|
27
|
-
| `@modern-js/runtime/bff`
|
|
28
|
-
| `@modern-js/runtime/server` | `@modern-js/server-runtime`
|
|
25
|
+
| 旧版路径 | 新版路径 | 说明 |
|
|
26
|
+
| --------------------------- | ------------------------------- | ---------------- |
|
|
27
|
+
| `@modern-js/runtime/bff` | `@modern-js/plugin-bff/runtime` | BFF 运行时路径 |
|
|
28
|
+
| `@modern-js/runtime/server` | `@modern-js/server-runtime` | 服务端运行时路径 |
|
|
29
29
|
|
|
30
30
|
## useRuntimeContext 已废弃
|
|
31
31
|
|
|
@@ -81,7 +81,6 @@ Modern.js 3.0 将 `server.ssr.mode` 的默认值从 `'string'` 改为 `'stream'`
|
|
|
81
81
|
|
|
82
82
|
对于 React 18 及以上项目,把 `ssr.mode` 的值由 `'stream'` 改为 `'string'`,不对 Data Loader 中的代码进行修改或使用 Suspense 的话,从渲染结果上没有任何影响。如果你的项目依赖了 React17,请把 `ssr.mode` 的值手动设置为 `'string'`。
|
|
83
83
|
|
|
84
|
-
|
|
85
84
|
## 使用 React Router v7
|
|
86
85
|
|
|
87
86
|
Modern.js 3.0 默认使用 React Router v7 作为路由库。React Router v7 相比 v6 只有少量的 [不兼容变更](https://reactrouter.com/upgrading/v6)。
|
|
@@ -182,9 +181,3 @@ antd v5 使用了 CSS-in-JS 方案,已原生支持按需加载,无需配置
|
|
|
182
181
|
## Eslint 规则集
|
|
183
182
|
|
|
184
183
|
Modern.js 之前提供了 ESLint 的完整规则集,涵盖了 @modern-js(针对 Node.js 项目的 Lint 规则)和 @modern-js-app(针对前端项目的 Lint 规则)。在 [v2.60.0](https://github.com/web-infra-dev/modern.js/releases/tag/v2.60.0) 版本中,我们正式移除了这些规则集。我们鼓励开发者根据自身需求选择合适的代码规范工具,直接使用 ESLint 并结合社区推荐的规则,或使用 Biome 以提升代码格式化的性能。
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
@@ -14,15 +14,13 @@ Modern.js 3.0 带来了多项重大改进和变化,主要包括:
|
|
|
14
14
|
- **SSG 能力完善**:提供完整的[静态站点生成(SSG)](/guides/basic-features/render/ssg)支持。
|
|
15
15
|
- **路由配置增强**:支持[配置式路由](/guides/basic-features/routes/config-routes),可单独使用或与[约定式路由](/guides/basic-features/routes/routes)结合,提供更灵活的路由定义方式。
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
## 升级前置检查
|
|
19
18
|
|
|
20
19
|
在开始升级之前,请确认:
|
|
21
20
|
|
|
22
21
|
1. 当前项目使用的是 Modern.js 2.0
|
|
23
22
|
2. 确定使用的 react 版本是 17 及以上
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
3. 确定使用的 node.js 版本是 18.20.8 及以上,推荐使用 node.js 22 以上版本
|
|
26
24
|
|
|
27
25
|
## 获取帮助
|
|
28
26
|
|
|
@@ -33,4 +31,3 @@ Modern.js 3.0 带来了多项重大改进和变化,主要包括:
|
|
|
33
31
|
- 加入 [Modern.js Discord 社区](https://discord.gg/modernjs)与其他开发者交流
|
|
34
32
|
|
|
35
33
|
我们建议在提交 issue 时提供尽可能详细的信息,包括错误日志、配置文件和复现步骤,以便更快地解决问题
|
|
36
|
-
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
这两种写法在旧版中互斥,迁移时请根据项目实际使用的能力选择对应路径。
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
## unstableMiddleware
|
|
12
11
|
|
|
13
12
|
### 核心差异
|
|
@@ -22,7 +21,10 @@
|
|
|
22
21
|
|
|
23
22
|
```typescript
|
|
24
23
|
// 旧版 - server/index.ts
|
|
25
|
-
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
24
|
+
export const unstableMiddleware: UnstableMiddleware[] = [
|
|
25
|
+
middleware1,
|
|
26
|
+
middleware2,
|
|
27
|
+
];
|
|
26
28
|
|
|
27
29
|
// 新版 - server/modern.server.ts
|
|
28
30
|
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
@@ -39,13 +41,22 @@ export default defineServerConfig({
|
|
|
39
41
|
|
|
40
42
|
```typescript
|
|
41
43
|
// 旧版
|
|
42
|
-
import type {
|
|
43
|
-
|
|
44
|
+
import type {
|
|
45
|
+
UnstableMiddleware,
|
|
46
|
+
UnstableMiddlewareContext,
|
|
47
|
+
} from '@modern-js/server-runtime';
|
|
48
|
+
const middleware: UnstableMiddleware = async (
|
|
49
|
+
c: UnstableMiddlewareContext,
|
|
50
|
+
next,
|
|
51
|
+
) => {
|
|
44
52
|
return c.response.raw('response'); // 不调用 next 也会继续渲染
|
|
45
53
|
};
|
|
46
54
|
|
|
47
55
|
// 新版
|
|
48
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
defineServerConfig,
|
|
58
|
+
type MiddlewareHandler,
|
|
59
|
+
} from '@modern-js/server-runtime';
|
|
49
60
|
const middleware: MiddlewareHandler = async (c, next) => {
|
|
50
61
|
await next(); // 必须调用
|
|
51
62
|
return c.text('response');
|
|
@@ -54,18 +65,17 @@ const middleware: MiddlewareHandler = async (c, next) => {
|
|
|
54
65
|
|
|
55
66
|
### Context API 对照
|
|
56
67
|
|
|
57
|
-
| 旧版 API
|
|
58
|
-
| -------------------- | ---------------------- |
|
|
59
|
-
| `c.request.cookie` | `getCookie(c, 'key')` | Cookie 读取
|
|
60
|
-
| `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 已废弃
|
|
61
|
-
| `c.request.pathname` | `c.req.path` | 请求路径
|
|
62
|
-
| `c.request.host` | `c.req.header('Host')` | 请求主机
|
|
63
|
-
| `c.request.query` | `c.req.query()` | 查询参数
|
|
64
|
-
| `c.request.headers` | `c.req.header()` | 请求头
|
|
65
|
-
| `c.response.status` | `c.status()` | 响应状态码
|
|
66
|
-
| `c.response.set` | `c.res.headers.set` | 设置响应头
|
|
67
|
-
| `c.response.raw` | `c.text` / `c.json` | 响应体
|
|
68
|
-
|
|
68
|
+
| 旧版 API | 新版 API | 说明 |
|
|
69
|
+
| -------------------- | ---------------------- | -------------- |
|
|
70
|
+
| `c.request.cookie` | `getCookie(c, 'key')` | Cookie 读取 |
|
|
71
|
+
| `c.req.cookie()` | `getCookie(c, 'key')` | Hono v4 已废弃 |
|
|
72
|
+
| `c.request.pathname` | `c.req.path` | 请求路径 |
|
|
73
|
+
| `c.request.host` | `c.req.header('Host')` | 请求主机 |
|
|
74
|
+
| `c.request.query` | `c.req.query()` | 查询参数 |
|
|
75
|
+
| `c.request.headers` | `c.req.header()` | 请求头 |
|
|
76
|
+
| `c.response.status` | `c.status()` | 响应状态码 |
|
|
77
|
+
| `c.response.set` | `c.res.headers.set` | 设置响应头 |
|
|
78
|
+
| `c.response.raw` | `c.text` / `c.json` | 响应体 |
|
|
69
79
|
|
|
70
80
|
## afterRender Hook
|
|
71
81
|
|
|
@@ -90,7 +100,10 @@ export const afterRender = (ctx, next) => {
|
|
|
90
100
|
};
|
|
91
101
|
|
|
92
102
|
// 新版 - server/modern.server.ts
|
|
93
|
-
import {
|
|
103
|
+
import {
|
|
104
|
+
defineServerConfig,
|
|
105
|
+
type MiddlewareHandler,
|
|
106
|
+
} from '@modern-js/server-runtime';
|
|
94
107
|
|
|
95
108
|
const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
96
109
|
await next(); // 先等待页面渲染
|
|
@@ -106,6 +119,8 @@ const renderMiddleware: MiddlewareHandler = async (c, next) => {
|
|
|
106
119
|
};
|
|
107
120
|
|
|
108
121
|
export default defineServerConfig({
|
|
109
|
-
renderMiddlewares: [
|
|
122
|
+
renderMiddlewares: [
|
|
123
|
+
{ name: 'custom-content-injection', handler: renderMiddleware },
|
|
124
|
+
],
|
|
110
125
|
});
|
|
111
126
|
```
|
package/docs/zh/index.md
CHANGED
|
@@ -39,29 +39,29 @@ export default myCliPlugin;
|
|
|
39
39
|
|
|
40
40
|
- **返回值:** `AppContext` 对象,包含以下字段:
|
|
41
41
|
|
|
42
|
-
| 字段名 | 类型
|
|
43
|
-
| ---------------------- |
|
|
44
|
-
| `command` | `string`
|
|
45
|
-
| `port` | `number`
|
|
46
|
-
| `configFile` | `string`
|
|
47
|
-
| `isProd` | `boolean`
|
|
48
|
-
| `appDirectory` | `string`
|
|
49
|
-
| `srcDirectory` | `string`
|
|
50
|
-
| `distDirectory` | `string`
|
|
51
|
-
| `sharedDirectory` | `string`
|
|
52
|
-
| `nodeModulesDirectory` | `string`
|
|
53
|
-
| `ip` | `string`
|
|
54
|
-
| `packageName` | `string`
|
|
55
|
-
| `plugins` | `object[]`
|
|
56
|
-
| `entrypoints` | `object[]`
|
|
57
|
-
| `serverRoutes` | `object[]`
|
|
58
|
-
| `bundlerType` | `rspack`
|
|
59
|
-
| `metaName` | `string`
|
|
60
|
-
| `apiDirectory` | `string`
|
|
61
|
-
| `lambdaDirectory` | `string`
|
|
62
|
-
| `runtimeConfigFile` | `string`
|
|
63
|
-
| `checkedEntries` | `string[]`
|
|
64
|
-
| `apiOnly` | `boolean`
|
|
42
|
+
| 字段名 | 类型 | 描述 | 何时可用 |
|
|
43
|
+
| ---------------------- | ---------- | -------------------------------------------------- | --------------------- |
|
|
44
|
+
| `command` | `string` | 当前执行的命令 (e.g., `dev`, `build`, `deploy`) | - |
|
|
45
|
+
| `port` | `number` | 开发服务器端口号 | `onPrepare` 之后 |
|
|
46
|
+
| `configFile` | `string` | 配置文件的绝对路径 | - |
|
|
47
|
+
| `isProd` | `boolean` | 是否为生产模式 | - |
|
|
48
|
+
| `appDirectory` | `string` | 项目根目录的绝对路径 | - |
|
|
49
|
+
| `srcDirectory` | `string` | 项目源码目录的绝对路径 | - |
|
|
50
|
+
| `distDirectory` | `string` | 项目产物输出目录的绝对路径 | `onPrepare`(及之后) |
|
|
51
|
+
| `sharedDirectory` | `string` | 公共模块目录的绝对路径 | - |
|
|
52
|
+
| `nodeModulesDirectory` | `string` | `node_modules` 目录的绝对路径 | - |
|
|
53
|
+
| `ip` | `string` | 当前机器的 IPv4 地址 | - |
|
|
54
|
+
| `packageName` | `string` | 项目 `package.json` 中的 `name` 字段 | - |
|
|
55
|
+
| `plugins` | `object[]` | 当前已注册的插件列表 | - |
|
|
56
|
+
| `entrypoints` | `object[]` | 页面入口信息 | - |
|
|
57
|
+
| `serverRoutes` | `object[]` | 服务端路由信息 | - |
|
|
58
|
+
| `bundlerType` | `rspack` | 当前使用的打包工具类型 | `onPrepare` 之后 |
|
|
59
|
+
| `metaName` | `string` | 框架内部名称 | - |
|
|
60
|
+
| `apiDirectory` | `string` | API 模块目录的绝对路径 (BFF 使用) | - |
|
|
61
|
+
| `lambdaDirectory` | `string` | Lambda 模块目录的绝对路径 (BFF 使用) | - |
|
|
62
|
+
| `runtimeConfigFile` | `string` | 运行时配置文件的名称 | - |
|
|
63
|
+
| `checkedEntries` | `string[]` | 指定的入口信息 | - |
|
|
64
|
+
| `apiOnly` | `boolean` | 是否为 `apiOnly` 模式 | - |
|
|
65
65
|
|
|
66
66
|
- **示例:**
|
|
67
67
|
|
|
@@ -236,7 +236,7 @@ api.modifyRspackConfig((config, utils) => {
|
|
|
236
236
|
config.builtins.minify = {
|
|
237
237
|
enable: true,
|
|
238
238
|
implementation: utils.rspack.SwcJsMinimizerRspackPlugin,
|
|
239
|
-
}
|
|
239
|
+
};
|
|
240
240
|
});
|
|
241
241
|
```
|
|
242
242
|
|
|
@@ -126,12 +126,12 @@ Rsbuild 是 Modern.js 底层的构建工具,通过添加 Rsbuild 插件可修
|
|
|
126
126
|
|
|
127
127
|
以下为已在 Modern.js 中内置的 Rsbuild 官方插件,无需安装,即可启用:
|
|
128
128
|
|
|
129
|
-
| 插件
|
|
130
|
-
|
|
|
131
|
-
| [React 插件](https://v2.rsbuild.rs/zh/plugins/list/plugin-react)
|
|
132
|
-
| [SVGR 插件](https://v2.rsbuild.rs/zh/plugins/list/plugin-svgr)
|
|
133
|
-
| [Assets Retry 插件](https://github.com/rstackjs/rsbuild-plugin-assets-retry)
|
|
134
|
-
| [Type Check 插件](https://github.com/rstackjs/rsbuild-plugin-type-check)
|
|
129
|
+
| 插件 | 介绍 | Modern.js 链接 |
|
|
130
|
+
| ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| [React 插件](https://v2.rsbuild.rs/zh/plugins/list/plugin-react) | 提供对 React 的支持 | - |
|
|
132
|
+
| [SVGR 插件](https://v2.rsbuild.rs/zh/plugins/list/plugin-svgr) | 支持将 SVG 图片转换为一个 React 组件 | [tools.svgr](/configure/app/tools/svgr) |
|
|
133
|
+
| [Assets Retry 插件](https://github.com/rstackjs/rsbuild-plugin-assets-retry) | 用于在静态资源加载失败时自动发起重试请求 | [output.assetsRetry](/configure/app/output/assets-retry.html) |
|
|
134
|
+
| [Type Check 插件](https://github.com/rstackjs/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/rstackjs/rsbuild-plugin-source-build) | 用于 monorepo 场景,支持引用其他子目录的源代码,并完成构建和热更新 | [experiments.sourceBuild](/configure/app/experiments/source-build.html) |
|
|
136
136
|
| [Check Syntax 插件](https://github.com/rstackjs/rsbuild-plugin-check-syntax) | 用于分析产物的语法兼容性,判断是否存在导致兼容性问题的高级语法 | [security.checkSyntax](/configure/app/security/check-syntax.html) |
|
|
137
137
|
| [CSS Minimizer 插件](https://github.com/rstackjs/rsbuild-plugin-css-minimizer) | 用于自定义 CSS 压缩工具,切换到 [cssnano](https://cssnano.co/) 或其他工具进行 CSS 压缩 | [tools.minifyCss](/configure/app/tools/minify-css.html) |
|
|
@@ -14,31 +14,26 @@ Modern.js 秉承“一切皆插件”的设计哲学,将框架的各项功能
|
|
|
14
14
|
## 插件类型与适用场景
|
|
15
15
|
|
|
16
16
|
**CLI 插件**:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
|
|
18
|
+
- **作用阶段**:构建时(执行 `modern` 命令时)。
|
|
19
|
+
- **典型场景**:
|
|
20
|
+
- 扩展命令行工具。
|
|
21
|
+
- 修改构建配置。
|
|
22
|
+
- 监听文件变化。
|
|
23
|
+
- 控制构建流程。
|
|
24
|
+
- **配置方式**:`modern.config.ts` 中的 `plugins` 字段。
|
|
24
25
|
|
|
25
26
|
**Runtime 插件**:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- **典型场景**:
|
|
37
|
-
- 添加自定义中间件。
|
|
38
|
-
- 扩展服务端 API。
|
|
39
|
-
- 定制化 SSR 逻辑。
|
|
40
|
-
- 与后端框架集成。
|
|
41
|
-
- **配置方式**:`server/modern.server.ts` 中的 `plugins` 字段。 */}
|
|
27
|
+
|
|
28
|
+
- **作用阶段**:应用运行时(浏览器/Node.js 环境)。
|
|
29
|
+
- **典型场景**:
|
|
30
|
+
- 初始化全局状态或服务。
|
|
31
|
+
- 封装 React 高阶组件(HOC)。
|
|
32
|
+
- 拦截或修改路由行为。
|
|
33
|
+
- 控制渲染流程。
|
|
34
|
+
- **配置方式**:`src/modern.runtime.ts` 中的 `plugins` 字段。
|
|
35
|
+
|
|
36
|
+
{/* **Server 插件**: - **作用阶段**:服务端请求处理阶段。 - **典型场景**: - 添加自定义中间件。 - 扩展服务端 API。 - 定制化 SSR 逻辑。 - 与后端框架集成。 - **配置方式**:`server/modern.server.ts` 中的 `plugins` 字段。 */}
|
|
42
37
|
|
|
43
38
|
## 插件结构
|
|
44
39
|
|
|
@@ -194,9 +189,7 @@ const myPlugin2 = () => ({
|
|
|
194
189
|
// 定义 Hooks
|
|
195
190
|
import { createSyncHook } from '@modern-js/plugin';
|
|
196
191
|
|
|
197
|
-
type RouteObject = {
|
|
198
|
-
/** TODO **/
|
|
199
|
-
};
|
|
192
|
+
type RouteObject = {/** TODO **/};
|
|
200
193
|
const modifyRoutes = createSyncHook<(routes: RouteObject[]) => RouteObject[]>();
|
|
201
194
|
|
|
202
195
|
// 插件中注册 Hooks
|
|
@@ -46,17 +46,17 @@ export default myServerPlugin;
|
|
|
46
46
|
|
|
47
47
|
- **返回值:** `ServerContext` 对象,包含以下字段:
|
|
48
48
|
|
|
49
|
-
| 字段名
|
|
50
|
-
|
|
|
51
|
-
| `middlewares`
|
|
52
|
-
| `renderMiddlewares` | `MiddlewareObj[]` | 渲染中间件列表
|
|
53
|
-
| `routes`
|
|
54
|
-
| `appDirectory`
|
|
55
|
-
| `apiDirectory`
|
|
56
|
-
| `lambdaDirectory`
|
|
57
|
-
| `sharedDirectory`
|
|
58
|
-
| `distDirectory`
|
|
59
|
-
| `plugins`
|
|
49
|
+
| 字段名 | 类型 | 描述 |
|
|
50
|
+
| ------------------- | ----------------- | -------------------------- |
|
|
51
|
+
| `middlewares` | `MiddlewareObj[]` | 中间件列表 |
|
|
52
|
+
| `renderMiddlewares` | `MiddlewareObj[]` | 渲染中间件列表 |
|
|
53
|
+
| `routes` | `ServerRoute[]` | 服务器路由信息 |
|
|
54
|
+
| `appDirectory` | `string` | 项目根目录的绝对路径 |
|
|
55
|
+
| `apiDirectory` | `string` | API 模块目录的绝对路径 |
|
|
56
|
+
| `lambdaDirectory` | `string` | Lambda 模块目录的绝对路径 |
|
|
57
|
+
| `sharedDirectory` | `string` | 公共模块目录的绝对路径 |
|
|
58
|
+
| `distDirectory` | `string` | 项目产物输出目录的绝对路径 |
|
|
59
|
+
| `plugins` | `ServerPlugin[]` | 当前已注册的插件列表 |
|
|
60
60
|
|
|
61
61
|
- **示例:**
|
|
62
62
|
|
|
@@ -111,7 +111,6 @@ await hooks.onPrepare.call();
|
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
|
|
115
114
|
## 上下文修改
|
|
116
115
|
|
|
117
116
|
#### `api.updateServerContext`
|
|
@@ -143,7 +142,6 @@ api.onPrepare(() => {
|
|
|
143
142
|
|
|
144
143
|
---
|
|
145
144
|
|
|
146
|
-
|
|
147
145
|
## 生命周期钩子
|
|
148
146
|
|
|
149
147
|
#### `api.onPrepare`
|
|
@@ -205,7 +203,6 @@ api.onReset(async ({ event }) => {
|
|
|
205
203
|
|
|
206
204
|
---
|
|
207
205
|
|
|
208
|
-
|
|
209
206
|
## 其他说明
|
|
210
207
|
|
|
211
208
|
- 可以参考 [Server 插件生命周期](./life-cycle.mdx) 了解插件钩子的执行顺序。
|
package/package.json
CHANGED
|
@@ -16,19 +16,18 @@
|
|
|
16
16
|
"modern",
|
|
17
17
|
"modern.js"
|
|
18
18
|
],
|
|
19
|
-
"version": "3.
|
|
19
|
+
"version": "3.10.0",
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"registry": "https://registry.npmjs.org/",
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"mermaid": "^11.
|
|
26
|
-
"@modern-js/sandpack-react": "3.
|
|
25
|
+
"mermaid": "^11.17.2",
|
|
26
|
+
"@modern-js/sandpack-react": "3.10.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"rsbuild-plugin-open-graph": "1.1.3",
|
|
30
29
|
"@rsbuild/plugin-sass": "2.0.1",
|
|
31
|
-
"@rspress/core": "2.0.
|
|
30
|
+
"@rspress/core": "2.0.23",
|
|
32
31
|
"@rspress/plugin-llms": "2.0.2",
|
|
33
32
|
"@rspress/shared": "2.0.2",
|
|
34
33
|
"@shikijs/transformers": "^3.23.0",
|
|
@@ -37,8 +36,9 @@
|
|
|
37
36
|
"classnames": "^2.5.1",
|
|
38
37
|
"clsx": "^1.2.1",
|
|
39
38
|
"fs-extra": "^10.1.0",
|
|
40
|
-
"react": "^19.
|
|
41
|
-
"react-dom": "^19.
|
|
39
|
+
"react": "^19.3.0",
|
|
40
|
+
"react-dom": "^19.3.0",
|
|
41
|
+
"rsbuild-plugin-open-graph": "1.1.3",
|
|
42
42
|
"ts-node": "^10.9.2",
|
|
43
43
|
"typescript": "^5"
|
|
44
44
|
},
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
"inputs": [
|
|
49
49
|
"build",
|
|
50
50
|
"^build",
|
|
51
|
-
"{projectRoot}/docs/**/*"
|
|
52
|
-
"{projectRoot}/rspress.config.ts"
|
|
51
|
+
"{projectRoot}/docs/**/*"
|
|
53
52
|
],
|
|
54
53
|
"outputs": [
|
|
55
54
|
"{projectRoot}/doc_build"
|
|
@@ -58,9 +57,8 @@
|
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
"scripts": {
|
|
61
|
-
"dev": "
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"preview": "rspress preview"
|
|
60
|
+
"dev": "rs doc",
|
|
61
|
+
"build": "rs doc build",
|
|
62
|
+
"preview": "rs doc preview"
|
|
65
63
|
}
|
|
66
64
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { pluginSass } from '@rsbuild/plugin-sass';
|
|
3
|
-
import { defineConfig } from '@rspress/core';
|
|
4
3
|
import { transformerNotationHighlight } from '@shikijs/transformers';
|
|
5
4
|
import { pluginOpenGraph } from 'rsbuild-plugin-open-graph';
|
|
5
|
+
import { define } from 'rstack';
|
|
6
6
|
|
|
7
|
-
const docPath = path.join(
|
|
7
|
+
const docPath = path.join(import.meta.dirname, 'docs');
|
|
8
8
|
const siteTitle = 'Modern.js';
|
|
9
9
|
const siteDescription =
|
|
10
10
|
'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.';
|
|
@@ -13,7 +13,7 @@ const socialDescription =
|
|
|
13
13
|
const socialImage =
|
|
14
14
|
'https://lf3-static.bytednsdoc.com/obj/eden-cn/nuvjhpqnuvr/modern-website/banner.jpeg';
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
define.doc({
|
|
17
17
|
root: docPath,
|
|
18
18
|
llms: true,
|
|
19
19
|
title: siteTitle,
|
|
@@ -22,7 +22,7 @@ export default defineConfig({
|
|
|
22
22
|
logo: 'https://lf-cdn-tos.bytescm.com/obj/static/webinfra/modern-js-website/assets/images/images/modernjs-logo.svg',
|
|
23
23
|
icon: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/uhbfnupenuhf/favicon.ico',
|
|
24
24
|
lang: 'en',
|
|
25
|
-
themeDir: path.join(
|
|
25
|
+
themeDir: path.join(import.meta.dirname, 'src'),
|
|
26
26
|
markdown: {
|
|
27
27
|
checkDeadLinks: true,
|
|
28
28
|
shiki: {
|
|
@@ -111,14 +111,11 @@ export default defineConfig({
|
|
|
111
111
|
output: {
|
|
112
112
|
dataUriLimit: 0,
|
|
113
113
|
},
|
|
114
|
-
dev: {
|
|
115
|
-
lazyCompilation: process.env.LAZY !== 'false',
|
|
116
|
-
},
|
|
117
114
|
resolve: {
|
|
118
115
|
alias: {
|
|
119
|
-
'@site-docs': path.join(
|
|
120
|
-
'@site-docs-en': path.join(
|
|
121
|
-
'@site':
|
|
116
|
+
'@site-docs': path.join(import.meta.dirname, './docs/zh'),
|
|
117
|
+
'@site-docs-en': path.join(import.meta.dirname, './docs/en'),
|
|
118
|
+
'@site': import.meta.dirname,
|
|
122
119
|
},
|
|
123
120
|
},
|
|
124
121
|
plugins: [
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
cursor: pointer;
|
|
10
10
|
border: 1px solid var(--rp-c-bg-soft);
|
|
11
11
|
background-color: var(--rp-c-bg-soft);
|
|
12
|
-
transition:
|
|
12
|
+
transition:
|
|
13
|
+
color 0.5s,
|
|
14
|
+
background-color 0.5s;
|
|
13
15
|
padding: 22px;
|
|
14
16
|
border-radius: 16px;
|
|
15
17
|
flex: 0 1 32%;
|