@modern-js/main-doc 2.0.0-beta.6 → 2.0.0-beta.7

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.
Files changed (76) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/index_.md +1 -1
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/pages.md +1 -1
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/routes.md +86 -0
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/router/router.md +176 -373
  6. package/en/docusaurus-plugin-content-docs/current/components/enable-bff.md +36 -0
  7. package/en/docusaurus-plugin-content-docs/current/components/global-proxy-config.md +74 -0
  8. package/en/docusaurus-plugin-content-docs/current/components/global-proxy.md +28 -0
  9. package/en/docusaurus-plugin-content-docs/current/components/router-legacy-tip.md +1 -0
  10. package/en/docusaurus-plugin-content-docs/current/configure/app/auto-load-plugin.md +62 -0
  11. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/proxy.md +2 -72
  12. package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +17 -2
  13. package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +0 -2
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/tailwindcss.md +16 -22
  15. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/_category_.json +8 -0
  16. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/bff-proxy.md +27 -0
  17. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/frameworks.md +150 -0
  18. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/function.md +222 -0
  19. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/index.md +20 -0
  20. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/bff/type.md +43 -0
  21. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/code-split.md +77 -0
  22. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/compatibility.md +76 -0
  23. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/eslint.md +145 -0
  24. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/index.md +12 -0
  25. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/low-level.md +46 -0
  26. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/ssg.md +132 -0
  27. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/ssr.md +306 -0
  28. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/testing.md +46 -0
  29. package/en/docusaurus-plugin-content-docs/current/guides/advanced-features/web-server.md +57 -0
  30. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/alias.md +67 -0
  31. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/tailwindcss.md +30 -35
  32. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +400 -0
  33. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/env-vars.md +166 -0
  34. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/html.md +235 -0
  35. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/mock.md +78 -0
  36. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/proxy.md +60 -0
  37. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +0 -2
  38. package/en/docusaurus-plugin-content-docs/current/guides/get-started/quick-start.md +2 -4
  39. package/package.json +3 -3
  40. package/zh/apis/app/hooks/src/index_.md +1 -1
  41. package/zh/apis/app/hooks/src/pages.md +1 -1
  42. package/zh/apis/app/hooks/src/routes.md +89 -0
  43. package/zh/apis/app/runtime/router/router.md +170 -368
  44. package/zh/components/debug-app.md +1 -2
  45. package/zh/components/enable-bff.md +36 -0
  46. package/zh/components/global-proxy-config.md +70 -0
  47. package/zh/components/micro-master-manifest-config.md +15 -0
  48. package/zh/components/router-legacy-tip.md +1 -0
  49. package/zh/configure/app/auto-load-plugin.md +62 -0
  50. package/zh/configure/app/deploy/microFrontend.md +0 -10
  51. package/zh/configure/app/dev/proxy.md +2 -70
  52. package/zh/configure/app/runtime/master-app.md +2 -16
  53. package/zh/configure/app/runtime/router.md +17 -3
  54. package/zh/configure/app/source/entries.md +1 -3
  55. package/zh/configure/app/tools/_category_.json +1 -1
  56. package/zh/configure/app/tools/tailwindcss.md +16 -23
  57. package/zh/guides/advanced-features/bff/frameworks.md +2 -0
  58. package/zh/guides/advanced-features/bff/function.md +44 -24
  59. package/zh/guides/advanced-features/code-split.md +28 -20
  60. package/zh/guides/advanced-features/compatibility.md +24 -14
  61. package/zh/guides/advanced-features/ssg.md +5 -47
  62. package/zh/guides/advanced-features/ssr.md +1 -1
  63. package/zh/guides/advanced-features/testing.md +2 -2
  64. package/zh/guides/basic-features/alias.md +5 -5
  65. package/zh/guides/basic-features/css/tailwindcss.md +31 -35
  66. package/zh/guides/basic-features/data-fetch.md +7 -6
  67. package/zh/guides/basic-features/env-vars.md +2 -2
  68. package/zh/guides/basic-features/html.md +62 -137
  69. package/zh/guides/basic-features/mock.md +8 -9
  70. package/zh/guides/basic-features/proxy.md +2 -2
  71. package/zh/guides/basic-features/routes.md +37 -6
  72. package/zh/guides/get-started/quick-start.md +1 -2
  73. package/zh/guides/topic-detail/framework-plugin/implement.md +54 -6
  74. package/zh/guides/topic-detail/micro-frontend/c02-development.md +1 -1
  75. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -31
  76. package/zh/configure/app/dev/with-master-app.md +0 -32
@@ -27,7 +27,7 @@ export default defineConfig({
27
27
  请求 `http://localhost:8080/go/api` 时,会从 [http://www.example.com/](http://www.example.com/) 返回响应内容。
28
28
 
29
29
  :::info 补充信息
30
- 配置格式可参考:【[http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware)】。
30
+ 配置格式可参考:[http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware)
31
31
  :::
32
32
 
33
33
  ## 全局代理
@@ -38,7 +38,7 @@ import GlobalProxy from '@site-docs/components/global-proxy.md'
38
38
 
39
39
  ## BFF 代理
40
40
 
41
- 通过配置 [`bff.proxy`](/docs/configure/app/bff/proxy) 可以代理 BFF API 请求到指定的服务上,和[开发环境代理](/docs/configure/app/dev/proxy)不同的是,它同样可以用在生产环境:
41
+ 通过配置 [`bff.proxy`](/docs/configure/app/bff/proxy) 可以代理 BFF API 请求到指定的服务上,上述两种代理不同,它同样可以用在生产环境:
42
42
 
43
43
  ```typescript title="modern.config.ts"
44
44
  export default defineConfig({
@@ -13,7 +13,7 @@ Modern.js 内置了对 [React Router 6](https://reactrouter.com/en/main) 的**
13
13
 
14
14
  以 `routes/` 为约定的入口,Modern.js 会自动基于文件系统,生成对应的路由结构。
15
15
 
16
- Modern.js 支持了业界流行的约定路由模式:**嵌套路由**,使用嵌套路由时,页面的路由 与 UI 结构是相呼应的,我们将会详细介绍这种路由模式。
16
+ Modern.js 支持了业界流行的约定式路由模式:**嵌套路由**,使用嵌套路由时,页面的路由 与 UI 结构是相呼应的,我们将会详细介绍这种路由模式。
17
17
 
18
18
  ```
19
19
  /user/johnny/profile /user/johnny/posts
@@ -26,11 +26,30 @@ Modern.js 支持了业界流行的约定路由模式:**嵌套路由**,使用
26
26
  +------------------+ +-----------------+
27
27
  ```
28
28
 
29
+
29
30
  ### 路由文件约定
30
31
 
31
- `routes/` 目录下有两个文件约定 `layout.[jt]sx` 和 `page.[jt]sx`(后面简写为 `.tsx`)。这两个文件决定了应用的布局层次,其中 `layout.tsx` 中作为布局组件,`page.tsx` 作为内容组件,是整个路由表的叶子节点。
32
+ 在`routes/` 目录下,目录名会作为路由 url 的映射,Modern.js 有两个文件约定 `layout.[jt]sx` 和 `page.[jt]sx`(后面简写为 `.tsx`)。这两个文件决定了应用的布局层次,其中 `layout.tsx` 中作为布局组件,`page.tsx` 作为内容组件,是整条路由的叶子节点(一条路由有且仅有一个叶子节点,且必须以叶子节点结尾)。
32
33
 
33
- 例如,这里 `routes/layout.tsx` 会作为 `/` 路由下所有组件的布局组件使用:
34
+ 例如以下目录结构:
35
+
36
+ ```bash
37
+ .
38
+ └── routes
39
+ ├── page.tsx
40
+ └── user
41
+ └── page.tsx
42
+ ```
43
+
44
+ 会产出下面两条路由:
45
+ - `/`
46
+ - `/user`
47
+
48
+ 当添加 `layout.tsx` 后, 假设有以下目录
49
+
50
+ :::info
51
+ 这里 `routes/layout.tsx` 会作为 `/` 路由下所有组件的布局组件使用, `routes/user/layout.tsx` 会作为 `/user` 路由下所有路由组件的布局组件使用。
52
+ :::
34
53
 
35
54
  ```bash
36
55
  .
@@ -64,6 +83,18 @@ Modern.js 支持了业界流行的约定路由模式:**嵌套路由**,使用
64
83
 
65
84
  `<Layout>` 组件是指 `routes/` 目录下所有 `layout.tsx` 文件,它们表示对应路由片段的布局,使用 `<Outlet>` 表示子组件。
66
85
 
86
+ ```tsx title=routes/layout.tsx
87
+ import { Link, Outlet, useLoaderData } from '@modern-js/runtime/router';
88
+
89
+ export default () => {
90
+ return (
91
+ <>
92
+ <Outlet></Outlet>
93
+ </>
94
+ )
95
+ }
96
+ ```
97
+
67
98
  :::note
68
99
  `<Outlet>` 是 React Router 6 中新的 API,详情可以查看 [Outlet](https://reactrouter.com/en/main/components/outlet#outlet).
69
100
  :::
@@ -130,6 +161,8 @@ Modern.js 支持了业界流行的约定路由模式:**嵌套路由**,使用
130
161
 
131
162
  在组件中,可以通过 [useParams](/docs/apis/app/runtime/router/#useparams) 获取对应命名的参数。
132
163
 
164
+ 在 loader 中,params 会作为 [loader](/docs/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params.xxx` 可以获取。
165
+
133
166
  ### 无路径布局
134
167
 
135
168
  当目录名以 __ 开头时,对应的目录名不会转换为实际的路由路径,例如以下文件目录:
@@ -217,6 +250,7 @@ Modern.js 会生成 `/login` 和 `/sign` 两条路由,`__auth/layout.tsx` 组
217
250
  ```
218
251
  :::info
219
252
  当目录的 layout 组件不存在时,该目录下的 loading 组件也不会生效。
253
+ Modern.js 建议必须有根 layout 和根 loading。
220
254
  :::
221
255
 
222
256
  当路由从 `/` 跳转到 `/blog` 时,如果 `blog/page` 组件的 JS Chunk 还未加载,则会先展示 `loading.tsx` 中导出的组件 UI。
@@ -272,9 +306,6 @@ export default () => {
272
306
 
273
307
  :::note
274
308
  在自控式路由下,开发者如果希望在 SSR 中使用 React Router 6 中 [Loader API](https://reactrouter.com/en/main/hooks/use-loader-data#useloaderdata) 的能力会相对复杂,推荐直接使用约定式路由。Modern.js 已经为你封装好了一切。
275
-
276
- <!-- Todo 嵌套路由带来的优化可以补充下文档-->
277
- 如果项目只想升级到 React Router 6,而不希望使用嵌套路由带来的优化,那 [useLoader](/docs/apis/app/runtime/core/use-loader) 在 SSR 下仍然可以工作。
278
309
  :::
279
310
 
280
311
  ## 其他路由方案
@@ -120,8 +120,7 @@ Starting the modern server...
120
120
  info App running at:
121
121
 
122
122
  > Local: http://localhost:8080/
123
- > Network: http://10.94.58.87:8080/
124
- > Network: http://10.254.68.105:8080/
123
+ > Network: http://192.168.0.1:8080/
125
124
  ```
126
125
 
127
126
  在浏览器中打开 `http://localhost:8000/`,内容应该和 `pnpm run dev` 时一致。
@@ -30,11 +30,23 @@ const MyPlugin = {
30
30
  };
31
31
  ```
32
32
 
33
- 另外,在插件中,允许配置与其他插件的执行顺序,详情可以参考[插件关系](/docs/guides/topic-detail/framework-plugin/relationship)。
33
+ 另外,在插件中,允许配置与其他插件的执行顺序。详情可以参考[插件关系](/docs/guides/topic-detail/framework-plugin/relationship)。
34
34
 
35
35
  ### 插件类型
36
36
 
37
- 使用 TypeScript 时,可以引入内置的 `CliPlugin` 类型,为插件提供正确的类型推导:
37
+ Modern-js 支持多种工程开发,如应用工程(app-tools), 模块工程(module-tools)等。
38
+
39
+ 为了兼顾不同工程开发的差异和通性,Modern-js 将插件如下图进行组织:
40
+
41
+ ![plugin-relationship](https://lf3-static.bytednsdoc.com/obj/eden-cn/eeeh7uhbepxlpe/modern-website/plugin-relationship.jpg)
42
+
43
+ 从图可以看出,Modern-js 将插件大致分为两类:
44
+
45
+ 1. 通用插件: 插件只会包含一些基础的 Hooks
46
+
47
+ 2. 工程插件: 不同的工程开发会在通用插件的基础上扩展出自己的 Hooks, Config 等类型。
48
+
49
+ 使用 TypeScript 时,可以引入内置的 `CliPlugin` 等类型,为插件提供正确的类型推导。
38
50
 
39
51
  ```ts
40
52
  import type { CliPlugin } from '@modern-js/core';
@@ -54,19 +66,55 @@ const MyPlugin: CliPlugin = {
54
66
  };
55
67
  ```
56
68
 
57
- Modern.js 导出的 `Plugin` 类型支持泛型扩展。
69
+ 上述代码为通用插件,只包含一些基础的 Hooks。 Modern.js 支持通过泛型对插件的定义进行扩展:
70
+
71
+ ```ts
72
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
58
73
 
59
- Modern.js 中,任意插件可以注册自己的 Hook,如果想拥有其他插件注册的 Hook 的类型,可以添加泛型:
74
+ const MyPlugin: CliPlugin<AppTools> = {
75
+ name: 'my-plugin',
76
+
77
+ setup() {
78
+ const foo = '1';
79
+
80
+ return {
81
+ afterBuild: () => {
82
+ // 在构建完成后执行逻辑
83
+ },
84
+ };
85
+ },
86
+ };
87
+ ```
88
+
89
+ 如果仔细观察 `AppTools` 这个类型,可以发现 `AppTools` 由 3 种类型构成.
90
+
91
+ ```ts
92
+ type AppTools = {
93
+ hooks: AppToolsHooks;
94
+ userConfig: AppToolsUserConfig;
95
+ normalizedConfig: AppToolsNormalizedConfig;
96
+ };
97
+ ```
98
+
99
+ 当编写插件时,插件通过泛型扩展在不同的基础上扩展自己的 Hooks 等类型:
60
100
 
61
101
  ```ts
102
+ // 通用插件上扩展
62
103
  import type { CliPlugin } from '@modern-js/core';
63
104
  import type { MyPluginHook } from 'xxx';
64
105
 
65
- const MyPlugin: CliPlugin<MyPluginHook> = {};
106
+ const MyPlugin: CliPlugin<{ hooks: MyPluginHook }> = {};
66
107
  ```
67
108
 
68
- 详细说明,请参考 [扩展 Hook](/docs/guides/topic-detail/framework-plugin/extend)。
109
+ ```ts
110
+ // 在 @modern-js/app-tools 基础上扩展
111
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
112
+ import type { MyPluginHook } from 'xxx';
113
+
114
+ const MyPlugin: CliPlugin<AppTools & { hooks: MyPluginHook }> = {};
115
+ ```
69
116
 
117
+ 详细说明,请参考 [扩展 Hook](/docs/guides/topic-detail/framework-plugin/extend)。
70
118
 
71
119
  ### 插件配置项
72
120
 
@@ -179,7 +179,7 @@ export default () => <div>Table Page</div>;
179
179
 
180
180
  访问主应用地址 `http://localhost:8080`,效果如下:
181
181
 
182
- ![demo](https://tosv.byted.org/obj/eden-internal/ozpmyhn_lm_hymuPild/ljhwZthlaukjlkulzlp/modernjs/micro-demo.gif)
182
+ ![demo](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/micro-demo.gif)
183
183
 
184
184
  在完成了微前端整体开发流程的体验后,你可以进一步了解如何 [开发主应用](./c03-main-app.md)
185
185
 
@@ -1,31 +0,0 @@
1
- ---
2
- sidebar_label: withMasterApp
3
- ---
4
-
5
- # dev.withMasterApp
6
-
7
- * Type: `Object`
8
- * Default: `null`
9
-
10
- When the project is a micro-front-end sub-application, you can use the `withMasterApp` configuration to enable the sub-application debugging mode.
11
-
12
- :::caution Caution
13
- When using child app debugging mode, you should first ensure that the main app has online debugging mode turned on.
14
- :::
15
-
16
- ```js title=modern.config.js
17
- export default defineConfig({
18
- dev: {
19
- withMasterApp: {
20
- //the path of the main application
21
- moduleApp: 'https://www.masterApp.com',
22
- //name of the subapplication
23
- moduleName: 'Contact'
24
- }
25
- }
26
- })
27
- ```
28
-
29
- - moduleApp: `string` Online address of the main application.
30
- - moduleName: `Contact` The name of the child app (needs to match the module name registered in the main app)。
31
-
@@ -1,32 +0,0 @@
1
- ---
2
- sidebar_label: withMasterApp
3
- ---
4
-
5
- # dev.withMasterApp
6
-
7
-
8
-
9
- * 类型: `Object`
10
- * 默认值: `null`
11
-
12
- 当项目为微前端子应用的时候,可以使用 `withMasterApp` 配置启用子应用调试模式。
13
-
14
- :::caution 注意
15
- 使用子应用调试的模式时,应该先确保主应用开启了线上 debug 模式。
16
- :::
17
-
18
- ```js title=modern.config.js
19
- export default defineConfig({
20
- dev: {
21
- withMasterApp: {
22
- // 主应用的路径
23
- moduleApp: 'https://www.masterApp.com',
24
- // 子应用的名称
25
- moduleName: 'Contact'
26
- }
27
- }
28
- })
29
- ```
30
-
31
- - moduleApp: `string` 主应用的线上地址。
32
- - moduleName: `Contact` 子应用的名称(需要和在主应用中注册的模块名匹配)。