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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +8 -3
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/inspect.md +33 -8
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/serve.md +32 -0
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/hooks/src/server.md +31 -0
  6. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +4 -3
  7. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/create-app.md +2 -3
  8. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/use-module-apps.md +1 -1
  9. package/en/docusaurus-plugin-content-docs/current/components/init-app.md +1 -1
  10. package/en/docusaurus-plugin-content-docs/current/configure/app/builder-plugins.md +70 -0
  11. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/with-master-app.md +0 -1
  12. package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +11 -5
  13. package/en/docusaurus-plugin-content-docs/current/configure/app/source/disable-entry-dirs.md +38 -0
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +66 -2
  15. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/esbuild.md +1 -1
  16. package/en/docusaurus-plugin-content-docs/current/guides/concept/entries.md +1 -1
  17. package/en/docusaurus-plugin-content-docs/current/guides/get-started/quick-start.md +3 -3
  18. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/_category_.json +4 -0
  19. package/en/docusaurus-plugin-content-docs/current/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
  20. package/package.json +3 -3
  21. package/zh/apis/app/commands/dev.md +9 -4
  22. package/zh/apis/app/commands/inspect.md +34 -9
  23. package/zh/apis/app/commands/{start.md → serve.md} +3 -3
  24. package/zh/apis/app/hooks/src/index_.md +1 -1
  25. package/zh/apis/app/hooks/src/server.md +31 -0
  26. package/zh/apis/app/runtime/core/bootstrap.md +3 -4
  27. package/zh/apis/app/runtime/core/create-app.md +1 -18
  28. package/zh/apis/app/runtime/core/use-module-apps.md +64 -33
  29. package/zh/apis/app/runtime/web-server/hook.md +1 -1
  30. package/zh/apis/app/runtime/web-server/middleware.md +1 -0
  31. package/zh/components/default-mwa-generate.md +5 -0
  32. package/zh/components/deploy.md +1 -0
  33. package/zh/components/enable-micro-frontend.md +13 -0
  34. package/zh/components/init-app.md +2 -2
  35. package/zh/components/micro-runtime-config.md +18 -0
  36. package/zh/components/prerequisites.md +2 -2
  37. package/zh/components/release-note.md +1 -0
  38. package/zh/configure/app/builder-plugins.md +72 -0
  39. package/zh/configure/app/deploy/_category_.json +4 -0
  40. package/zh/configure/app/deploy/microFrontend.md +64 -0
  41. package/zh/configure/app/dev/with-master-app.md +0 -2
  42. package/zh/configure/app/plugins.md +10 -4
  43. package/zh/configure/app/runtime/master-app.md +33 -36
  44. package/zh/configure/app/source/disable-entry-dirs.md +37 -0
  45. package/zh/configure/app/source/entries-dir.md +0 -3
  46. package/zh/configure/app/source/entries.md +66 -3
  47. package/zh/guides/advanced-features/compatibility.md +12 -1
  48. package/zh/guides/advanced-features/eslint.md +21 -21
  49. package/zh/guides/advanced-features/ssg.md +14 -3
  50. package/zh/guides/advanced-features/ssr.md +1 -1
  51. package/zh/guides/advanced-features/testing.md +11 -0
  52. package/zh/guides/advanced-features/web-server.md +12 -1
  53. package/zh/guides/basic-features/css/tailwindcss.md +11 -0
  54. package/zh/guides/basic-features/data-fetch.md +398 -5
  55. package/zh/guides/basic-features/routes.md +35 -3
  56. package/zh/guides/concept/entries.md +104 -14
  57. package/zh/guides/get-started/quick-start.md +8 -5
  58. package/zh/guides/get-started/upgrade.md +3 -1
  59. package/zh/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
  60. package/zh/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
  61. package/zh/guides/topic-detail/micro-frontend/c02-development.md +191 -0
  62. package/zh/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
  63. package/zh/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
  64. package/zh/guides/topic-detail/micro-frontend/{mixed-stack.md → c05-mixed-stack.md} +3 -3
  65. package/zh/guides/topic-detail/monorepo/create-sub-project.md +2 -2
  66. package/zh/tutorials/first-app/c01-start.md +9 -4
  67. package/zh/tutorials/first-app/c03-css.md +19 -0
  68. package/zh/tutorials/first-app/c04-routes.md +4 -4
  69. package/zh/tutorials/first-app/c05-loader.md +3 -3
  70. package/zh/tutorials/first-app/c06-model.md +19 -19
  71. package/zh/tutorials/first-app/c07-container.md +38 -23
  72. package/zh/tutorials/first-app/c08-entries.md +4 -1
  73. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +0 -32
  74. package/zh/guides/advanced-features/custom-app.md +0 -70
  75. package/zh/guides/topic-detail/micro-frontend/communicate.md +0 -39
  76. package/zh/guides/topic-detail/micro-frontend/debugging.md +0 -168
  77. package/zh/guides/topic-detail/micro-frontend/introduction.md +0 -13
  78. package/zh/guides/topic-detail/micro-frontend/route-mode.md +0 -110
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: "*.[server|node].[tj]sx"
3
+ sidebar_position: 8
4
+ ---
5
+
6
+ 应用项目中使用,用于放置服务端代码,一般有以下两个作用:
7
+
8
+ 1. 当 `*.tsx` 和 `*.[server|node].tsx` 共存时,SSR 在服务端执行渲染时,会优先使用 `*.[server|node].tsx` 文件,而不是 `*.tsx` 文件。
9
+
10
+ 2. 在使用 [data loader](/docs/guides/basic-features/data-fetch) 时,需要将服务端的依赖从该文件中做重导出
11
+
12
+ ```tsx
13
+ // routes/user/avatar.tsx
14
+ import { useLoaderData } from '@modern-js/runtime/router';
15
+ import { readFile } from './utils.server';
16
+
17
+ type ProfileData = { /* some type declarations */ }
18
+
19
+ export const loader = async(): ProfileData => {
20
+ const profile = await readFile('profile.json');
21
+ return profile;
22
+ }
23
+
24
+ export default function UserPage() {
25
+ const profileData = useLoaderData() as ProfileData;
26
+ return <div>{profileData}</div>;
27
+ }
28
+
29
+ // routes/user/utils.server.ts
30
+ export * from 'fs-extra';
31
+ ```
@@ -2,7 +2,7 @@
2
2
  title: bootstrap
3
3
  ---
4
4
 
5
- 用于启动和挂载应用,通常情况下不做手动调用。只有在使用[自定义入口](/docs/guides/advanced-features/custom-app)时,才需要使用该 API。
5
+ 用于启动和挂载应用,通常情况下不做手动调用。只有在使用[自定义 App](/docs/guides/concept/entries#自定义-app) 时,才需要使用该 API。
6
6
 
7
7
  ## 使用姿势
8
8
 
@@ -32,7 +32,7 @@ type BootStrap<T = unknown> = (
32
32
  ### 参数
33
33
 
34
34
  - `AppComponent`:通过 [`createApp`](./create-app) 创建的 ReactElement 实例。
35
- - `rootId`:要挂载的 DOM 根元素 id,如 `"root"`。
35
+ - `id`:要挂载的 DOM 根元素 id,如 `"root"`。
36
36
  - `root`: ReactDOM.createRoot 的返回值,用于 bootstrap 函数外需要 root 销毁组件的场景。
37
37
  - `ReactDOM`: ReactDOM 对象,用于区分 React 18 和 React 17 API。
38
38
 
@@ -41,7 +41,6 @@ type BootStrap<T = unknown> = (
41
41
  ```tsx
42
42
  import ReactDOM from 'react-dom/client'
43
43
  import { createApp, bootstrap } from '@modern-js/runtime';
44
- import { router, state } from '@modern-js/runtime/plugins';
45
44
 
46
45
  function App() {
47
46
  return <div>Hello Modern.js</div>;
@@ -49,7 +48,7 @@ function App() {
49
48
 
50
49
  const WrappedApp = createApp({
51
50
  // 传入自定义插件
52
- plugins: [router({}), state({})],
51
+ plugins: [customPlugin()],
53
52
  })(App);
54
53
 
55
54
  bootstrap(WrappedApp, 'root', undefined, ReactDOM);
@@ -2,7 +2,7 @@
2
2
  title: createApp
3
3
  ---
4
4
 
5
- 用于创建自定义入口,定制运行时插件。只有在使用[自定义入口](/docs/guides/advanced-features/custom-app)时,才需要使用该 API。
5
+ 用于创建自定义入口,定制运行时插件。只有在使用[自定义 App](/docs/guides/concept/entries#自定义-app) 时,才需要使用该 API。
6
6
 
7
7
  ## 使用姿势
8
8
 
@@ -28,20 +28,3 @@ function createApp(options: { plugins: Plugin[] }): React.ComponentType<any>;
28
28
  ### 创建自定义入口
29
29
 
30
30
  详见 [`bootstrap`](./bootstrap.md)。
31
-
32
- ### 定制插件
33
-
34
- ```ts
35
- import { createApp } from '@modern-js/runtime';
36
-
37
- function App() {
38
- return <div>app</div>;
39
- }
40
-
41
- export default createApp({
42
- plugins: [
43
- router({}),
44
- state({}),
45
- ]
46
- })(App);
47
- ```
@@ -7,19 +7,9 @@ title: useModuleApps
7
7
  ## 使用姿势
8
8
 
9
9
  ```tsx
10
- import { useModuleApps } from '@modern/plugin-garfish';
10
+ import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
11
11
  ```
12
12
 
13
- :::info 开启微前端
14
- 该 API 在微前端主应用中使用,请先执行 `pnpm run new` 开启微前端功能。
15
-
16
- ```bash
17
- pnpm run new
18
- ? 请选择你想要的操作 启用可选功能
19
- ? 启用可选功能 启用「微前端」模式
20
- ```
21
- :::
22
-
23
13
  ## 函数签名
24
14
 
25
15
  `function useModuleApps(): Record<string, React.FC<any>>`
@@ -29,31 +19,14 @@ pnpm run new
29
19
  ## 示例
30
20
 
31
21
  需要先配置微前端子应用信息。
22
+ import EnableMicroFrontend from '@site-docs/components/enable-micro-frontend.md';
23
+
24
+ <EnableMicroFrontend />
32
25
 
33
- ```ts title=modern.config.js
34
- module.exports = {
35
- runtime: {
36
- features:{
37
- masterApp: {
38
- apps: [
39
- {
40
- name: 'Home',
41
- entry: 'http://www.home.com'
42
- },
43
- {
44
- name: 'Contact',
45
- entry: 'http://www.contact.com'
46
- },
47
- ]
48
- }
49
- }
50
- }
51
- }
52
- ```
53
26
 
54
27
  ```tsx title=App.tsx
55
28
  function App() {
56
- const { Components: { Home, Contact } } = useModuleApps();
29
+ const { Home, Contact } = useModuleApps();
57
30
 
58
31
  return <div>
59
32
  Master APP
@@ -65,18 +38,76 @@ function App() {
65
38
  </Route>
66
39
  </div>;
67
40
  }
41
+
42
+ defineConfig(App, {
43
+ masterApp: {
44
+ apps: [
45
+ {
46
+ // name 区分大小写,name 提供的是什么 useModuleApps 返回的就是什么
47
+ name: "Home",
48
+ entry: "http://127.0.0.1:8081/"
49
+ },
50
+ {
51
+ name: "Contact",
52
+ entry: "http://localhost:8082"
53
+ }
54
+ ]
55
+ }
56
+ })
68
57
  ```
69
58
 
70
59
  通过 `useModuleApps()` 获取到 `Home` 和 `Contact` 子应用组件(名称和配置里的 `name` 字段对应),之后就可以像使用普通的 React 组件一样去加载子应用。
71
60
 
72
61
 
62
+ ### 集中式路由
63
+
64
+ **集中式路由** 是将子应用的激活路由集中配置的方式。我们给子应用列表信息添加 `activeWhen` 字段来启用 **集中式路由**。
65
+
66
+
67
+ <MicroRuntimeConfig />
68
+
69
+ 然后在主应用中使用 `useModuleApp` 方法获取 `MApp` 组件, 并在主应用渲染 `MApp`。
70
+
71
+ ```tsx title=主应用:App.tsx
72
+ import { useModuleApp } from '@modern-js/plugin-runtime';
73
+
74
+ function App() {
75
+ const { MApp } = useModuleApps();
76
+
77
+ return <div>
78
+ <MApp />
79
+ </div>
80
+ }
81
+
82
+ defineConfig(App, {
83
+ masterApp: {
84
+ apps: [
85
+ {
86
+ // name 区分大小写,name 提供的是什么 useModuleApps 返回的就是什么
87
+ name: "Dashboard",
88
+ activeWhen: '/dashboard',
89
+ entry: "http://127.0.0.1:8081/"
90
+ },
91
+ {
92
+ name: "TableList",
93
+ activeWhen: '/table',
94
+ entry: "http://localhost:8082"
95
+ }
96
+ ]
97
+ }
98
+ })
99
+ ```
100
+
101
+ 这样启动应用后,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用,访问 `/table` 路由,会渲染 `TableList` 子应用。
102
+
103
+
73
104
  ## 加载动画
74
105
 
75
106
  可以通过以下方式,自定义组件加载过程的过渡动画。
76
107
 
77
108
  ```tsx title=App.tsx
78
109
  function App() {
79
- const { Components: { Home } } = useModuleApps();
110
+ const { Home } = useModuleApps();
80
111
 
81
112
  return <div>
82
113
  Master APP
@@ -46,6 +46,7 @@ type HookContext = {
46
46
  ) => void;
47
47
  };
48
48
  request: {
49
+ url: string;
49
50
  host: string;
50
51
  pathname: string;
51
52
  query: Record<string, any>;
@@ -82,7 +83,6 @@ type AfterRenderContext = {
82
83
  };
83
84
  ```
84
85
 
85
-
86
86
  ### 参数
87
87
 
88
88
  - `context`:提供当前 Hook 上下文。
@@ -53,6 +53,7 @@ type MiddlewareContext = {
53
53
  locals: Record<string, any>;
54
54
  };
55
55
  request: {
56
+ url: string;
56
57
  host: string;
57
58
  pathname: string;
58
59
  query: Record<string, any>;
@@ -0,0 +1,5 @@
1
+ ```bash
2
+ ? 请选择你想创建的工程类型 应用
3
+ ? 请选择开发语言 TS
4
+ ? 请选择包管理工具 pnpm
5
+ ```
@@ -0,0 +1 @@
1
+ 本地验证完成后,可以将 `dist/` 下的产物整理成服务器需要的结构,进行部署。
@@ -0,0 +1,13 @@
1
+ ```javascript title="modern.config.ts"
2
+ import AppToolPlugin, { defineConfig } from '@modern-js/app-tools';
3
+ import GarfishPlugin from '@modern-js/plugin-garfish';
4
+
5
+ export default defineConfig({
6
+ runtime: {
7
+ router: true,
8
+ state: true,
9
+ masterApp: true,
10
+ },
11
+ plugins: [AppToolPlugin(), GarfishPlugin()],
12
+ });
13
+ ```
@@ -15,8 +15,8 @@ Modern.js 生成器会提供一个可交互的问答界面,根据结果初始
15
15
  [INFO] 创建成功!
16
16
  可在新项目的目录下运行以下命令:
17
17
  pnpm run dev # 按开发环境的要求,运行和调试项目
18
- pnpm run build # 按产品环境的要求,构建项目
19
- pnpm run start # 按产品环境的要求,运行项目
18
+ pnpm run build # 按生产环境的要求,构建项目
19
+ pnpm run serve # 按生产环境的要求,运行项目
20
20
  pnpm run lint # 检查和修复所有代码
21
21
  pnpm run new # 继续创建更多项目要素,比如应用入口
22
22
  ```
@@ -0,0 +1,18 @@
1
+ ```javascript title="src/App.tsx"
2
+ import { defineConfig } from '@modern-js/runtime';
3
+
4
+ defineConfig(App, {
5
+ masterApp: {
6
+ apps: [
7
+ {
8
+ name: 'DashBoard',
9
+ entry: 'http://127.0.0.1:8081/',
10
+ },
11
+ {
12
+ name: 'TableList',
13
+ entry: 'http://localhost:8082',
14
+ },
15
+ ],
16
+ },
17
+ });
18
+ ```
@@ -1,10 +1,10 @@
1
1
  ### Node.js
2
2
 
3
- 需要 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 16.18.1
3
+ 需要 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 v16.18.1
4
4
 
5
5
  Modern.js 推荐在开发环境里先安装 [nvm](https://github.com/nvm-sh/nvm#install--update-script),在 shell 里集成[自动切换 node 版本的脚本](https://github.com/nvm-sh/nvm#deeper-shell-integration)。
6
6
 
7
- 然后只要仓库根目录下有内容为 `lts/fermium` 或 `lts/gallium` 的 `.nvmrc` 文件,进入这个仓库时就会自动安装或切换到正确的 Node.js 版本。
7
+ 然后只要仓库根目录下有内容为 `lts/gallium` 的 `.nvmrc` 文件,进入这个仓库时就会自动安装或切换到正确的 Node.js 版本。
8
8
 
9
9
  ### pnpm
10
10
 
@@ -0,0 +1 @@
1
+ 根据官网 [Release Note](https://github.com/modern-js-dev/modern.js/releases/tag/v1.22.1),开发者也可以手动将项目升级到想要的版本。
@@ -0,0 +1,72 @@
1
+ ---
2
+ title: builderPlugins (构建插件)
3
+ sidebar_position: 10
4
+ ---
5
+
6
+ - 类型:`BuilderPlugin[]`
7
+ - 默认值:`[]`
8
+
9
+ 用于配置 Modern.js Builder 构建插件。
10
+
11
+ Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力](/docs/guides/basic-features/builder) 了解相关背景。
12
+
13
+ 如果你想了解 Builder 插件的编写方式,可以参考 [Modern.js Builder - 插件系统](https://modernjs.dev/builder/zh/plugins/introduction.html)。
14
+
15
+ ## 注意事项
16
+
17
+ 该选项**用于配置 Modern.js Builder 构建插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
18
+
19
+ - 配置 Modern.js 框架插件,请使用 [plugins](docs/configure/app/plugins) 配置项。
20
+ - 配置 webpack 插件,请使用 [tools.webpack](/docs/configure/app/tools/webpack) 或 [tools.webpackChain](/docs/configure/app/tools/webpack-chain) 配置项。
21
+ - 配置 Babel 插件,请使用 [tools.babel](/docs/configure/app/tools/babel) 配置项。
22
+
23
+ ## 何时使用
24
+
25
+ 大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](docs/configure/app/plugins) 字段进行注册。因为框架插件提供的 API 更丰富、能力更强,而 Builder 插件提供的 API 只能用于构建场景。
26
+
27
+ 当你需要引用一些现有的 Builder 插件(并且在 Modern.js 中没有相关能力),或是在不同的框架之间复用 Builder 插件时,你可以使用 `builderPlugins` 字段进行注册。
28
+
29
+ ## 示例
30
+
31
+ 下面是 Builder 插件的使用示例。
32
+
33
+ ### 使用 npm 上的插件
34
+
35
+ 使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。
36
+
37
+ ```ts title="modern.config.ts"
38
+ import MyBuilderPlugin from 'my-builder-plugin';
39
+
40
+ export default defineConfig({
41
+ builderPlugins: [MyBuilderPlugin()],
42
+ });
43
+ ```
44
+
45
+ ### 使用本地插件
46
+
47
+ 使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。
48
+
49
+ ```ts title="modern.config.ts"
50
+ import MyBuilderPlugin from './plugin/myBuilderPlugin';
51
+
52
+ export default defineConfig({
53
+ builderPlugins: [MyBuilderPlugin()],
54
+ });
55
+ ```
56
+
57
+ ### 插件配置项
58
+
59
+ 如果插件提供了一些自定义的配置项,可以通过插件函数的参数传入配置。
60
+
61
+ ```ts title="modern.config.ts"
62
+ import MyBuilderPlugin from 'my-builder-plugin';
63
+
64
+ export default defineConfig({
65
+ builderPlugins: [
66
+ MyBuilderPlugin({
67
+ foo: 1,
68
+ bar: 2,
69
+ }),
70
+ ],
71
+ });
72
+ ```
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "deploy (部署)",
3
+ "position": 8
4
+ }
@@ -0,0 +1,64 @@
1
+ ---
2
+ sidebar_label: microFrontend
3
+ ---
4
+
5
+ # deploy.microFrontend
6
+
7
+ * 类型:`object`
8
+ * 默认值:`{enableHtmlEntry: true, externalBasicLibrary: false}`
9
+
10
+ ```ts
11
+ interface MicroFrontend {
12
+ enableHtmlEntry?: boolean;
13
+ externalBasicLibrary?: boolean;
14
+ moduleApp?: string;
15
+ }
16
+ ```
17
+
18
+ 开发者可使用 `deploy.microFrontend` 属性来配置微前端子应用的信息。
19
+
20
+ :::caution 注意
21
+ 需要先通过 `pnpm run new` 启用「微前端」 功能。
22
+ :::
23
+
24
+ ## 示例
25
+
26
+ ```ts
27
+ export default defineConfig({
28
+ deploy: {
29
+ microFrontend: {
30
+ enableHtmlEntry: true
31
+ }
32
+ }
33
+ });
34
+ ```
35
+
36
+ ## 配置项
37
+
38
+ ### enableHtmlEntry
39
+
40
+ * 类型:`boolean`
41
+
42
+ * 默认值:`true`
43
+
44
+ * 是否启用 html 入口的功能,默认为 `true`,将子应用构建成 `HTML` 模式,Garfish 支持了 `html` 入口,可以开启开选项,体验对应功能,为 HTML 入口时直接将子应用 entry 指向子应用的 html 即可
45
+ * 可以通过设置为 `false`, 表明子应用构建为 `js`,构建为 `js` 后子应用无法独立运行,为 `JS` 入口时将子应用的入口文件指向子应用的 `JS`
46
+
47
+
48
+ ### externalBasicLibrary
49
+
50
+ * 类型:`boolean`
51
+
52
+ * 默认值:`false`
53
+
54
+ 是否 `external` 基础库,当设置为 `true` 时,当前子应用将会 `external`:`react`、`react-dom`,`EdenX` 主应用会自动 `setExternal` 这两个基础库,如果其他类型的框架请通过 `Garfish.setExternal` 增加 `react`、`react-dom` 依赖
55
+
56
+
57
+ ### moduleApp
58
+
59
+ * 类型:`string`
60
+
61
+ * 默认值:`undefined`
62
+
63
+ 该值可以配置子应用的名称,目前主要结合 [`dev.withMasterApp`](/docs/configure/app/dev/with-master-app) 进行测试。
64
+
@@ -30,5 +30,3 @@ export default defineConfig({
30
30
 
31
31
  - moduleApp: `string` 主应用的线上地址。
32
32
  - moduleName: `Contact` 子应用的名称(需要和在主应用中注册的模块名匹配)。
33
-
34
- 详细使用方式,请参考【[微前端子应用](/docs/guides/topic-detail/micro-frontend/debugging)】。
@@ -3,18 +3,24 @@ title: plugins (插件)
3
3
  sidebar_position: 9
4
4
  ---
5
5
 
6
- - 类型: `CliPlugin[]`
6
+ - 类型:`CliPlugin[]`
7
7
  - 默认值:`[]`
8
8
 
9
- 用于配置自定义的 Modern.js 插件。
9
+ 用于配置自定义的 Modern.js 框架插件。
10
10
 
11
11
  自定义插件的编写方式请参考 [如何编写插件](/docs/guides/topic-detail/framework-plugin/implement)。
12
12
 
13
- 该选项用于配置框架插件,如果需要配置 webpack 插件,请使用 [tools.webpack](/docs/configure/app/tools/webpack) 或 [tools.webpackChain](/docs/configure/app/tools/webpack-chain); 需要配置 babel 插件,请使用 [tools.babel](/docs/configure/app/tools/babel)。
13
+ ## 注意事项
14
+
15
+ 该选项**用于配置框架插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
16
+
17
+ - 配置 Modern.js Builder 插件,请使用 [builderPlugins](docs/configure/app/builder-plugins) 配置项。
18
+ - 配置 webpack 插件,请使用 [tools.webpack](/docs/configure/app/tools/webpack) 或 [tools.webpackChain](/docs/configure/app/tools/webpack-chain) 配置项。
19
+ - 配置 Babel 插件,请使用 [tools.babel](/docs/configure/app/tools/babel) 配置项。
14
20
 
15
21
  ## 插件类型
16
22
 
17
- Modern.js 中内置了三种不同的插件机制:
23
+ Modern.js 中内置了三种不同的框架插件:
18
24
 
19
25
  - `CLI 插件`,适用于本地开发、编译构建阶段,可以在命令行和编译阶段扩展各种能力。
20
26
  - `Server 插件`,适用于服务端。
@@ -6,54 +6,51 @@ sidebar_label: masterApp
6
6
 
7
7
  * 类型: `Object`
8
8
 
9
- :::info
10
- 使用该配置首先需要使用 [new 命令](/docs/apis/app/commands/new)启用「微前端」功能。
9
+ :::caution 注意
10
+ 需要先通过 `pnpm run new` 启用「微前端」 功能。
11
11
  :::
12
- ## `manifest`
13
12
 
14
- 主应用添加子应用信息。
13
+ ## 示例
15
14
 
16
- * 类型:`modules: Array<{
17
- name: string;
18
- entry: string;
19
- activeWhen?: string;
20
- }> | string;`
21
- * 默认值:`null`
15
+ import EnableMicroFrontend from '@site-docs/components/enable-micro-frontend.md';
22
16
 
23
- ### `modules`
17
+ <EnableMicroFrontend />
24
18
 
25
- `modules` 为对象类型的时候,表示子应用模块的信息。
19
+ ## `manifest`
26
20
 
27
- - name: 子应用的名称。
28
- - entry: 子应用的入口。
29
- - activeWhen?: 子应用激活路径。
21
+ ```ts
22
+ interface Manifest {
23
+ getAppList?: ()=> Array<AppInfo>
24
+ }
25
+ ```
30
26
 
31
- `modules` 为 `string` 时,是一个 url 地址,请求该地址可以拿到和 `modules` 对象格式一样的数据结构。
27
+ #### `getAppList?`
32
28
 
33
- ## `LoadingComponent`
29
+ 通过 `getAppList` 配置,可以自定义如何获取远程列表数据
34
30
 
35
- * 类型: `React.ComponentType | React.ElementType`
36
- * 默认值 `null`
31
+ ```ts
32
+ type GetAppList = ()=> Promise<Array<AppInfo>>;
33
+ ```
37
34
 
38
- 当加载或切换子应用的时候,加载的过渡动画。
39
35
 
40
- `LoadingComponent` 需要通过 [defineConfig](/docs/apis/app/runtime/app/define-config) 配置。
36
+ ### apps
41
37
 
42
- ```tsx
43
- import { defineConfig } from '@modern-js/runtime';
38
+ 当 `apps` 为对象类型的时候,表示子应用模块的信息 `Array<AppInfo>`
44
39
 
45
- function App() {
46
- ...
40
+ ```ts
41
+ interface AppInfo {
42
+ name: string;
43
+ entry: string;
44
+ activeWhen?: string | ()=> boolean;
47
45
  }
48
-
49
- defineConfig(
50
- App,
51
- {
52
- masterApp: {
53
- LoadingComponent: () => {
54
- return <div>loading...</div>
55
- }
56
- }
57
- }
58
- )
59
46
  ```
47
+
48
+ - name: 子应用的名称。
49
+ - entry: 子应用的入口。
50
+ - activeWhen?: 子应用激活路径。
51
+
52
+ ### 其他配置项
53
+
54
+ 在 `masterApp` 配置下,开发者可以透传 Garfish 的配置项。
55
+
56
+ 所有支持的配置项[点此查看](https://garfishjs.org/api/run/#%E5%8F%82%E6%95%B0)
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: source.disableEntryDirs
3
+
4
+ sidebar_label: disableEntryDirs
5
+ ---
6
+
7
+ * 类型: `string[]`
8
+ * 默认值: `[]`
9
+
10
+ 默认会根据 `src` 目录识别应用入口,可通过该选项禁止某些目录被识别为应用入口。
11
+
12
+ 例如,当配置与目录结构如下时:
13
+
14
+ ```typescript title="modern.config.ts"
15
+ export default defineConfig({
16
+ source: {
17
+ disableEntryDirs: './src/one'
18
+ }
19
+ })
20
+ ```
21
+
22
+ ``` title="项目目录结构"
23
+ └── src/
24
+ ├── one/
25
+ | └── App.tsx
26
+ ├── two/
27
+ | └── routes/
28
+ └── env.d.ts
29
+ ```
30
+
31
+ 在未设置该配置项时,Modern.js 会根据项目目录产出两个 entry:
32
+ - one
33
+ - two
34
+
35
+ 当设置该配置项后,`src/one` 不会作为 entry 目录被识别。
36
+
37
+ 常见的用法是,将 `src/common`、`src/components` 目录配置到该选项中,避免这些目录被识别为应用入口。
@@ -4,12 +4,9 @@ title: source.entriesDir
4
4
  sidebar_label: entriesDir
5
5
  ---
6
6
 
7
-
8
-
9
7
  * 类型: `string`
10
8
  * 默认值: `./src`
11
9
 
12
-
13
10
  默认会根据 `src` 目录识别应用入口,可通过该选项自定义应用入口的识别目录。
14
11
 
15
12
  例如,当配置与目录结构如下时: