@modern-js/main-doc 2.0.0-beta.3 → 2.0.0-beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) 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 +31 -10
  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 +42 -0
  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/server/routes.md +2 -4
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/source/disable-entry-dirs.md +38 -0
  15. package/en/docusaurus-plugin-content-docs/current/configure/app/source/entries.md +66 -2
  16. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/esbuild.md +16 -39
  17. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/css-in-js.md +38 -0
  18. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/css-modules.md +86 -0
  19. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/less-sass.md +17 -0
  20. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/postcss.md +81 -0
  21. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/css/tailwindcss.md +95 -0
  22. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/data-fetch.md +66 -0
  23. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/routes.md +270 -0
  24. package/en/docusaurus-plugin-content-docs/current/guides/concept/entries.md +116 -0
  25. package/en/docusaurus-plugin-content-docs/current/guides/get-started/quick-start.md +162 -0
  26. package/en/docusaurus-plugin-content-docs/current/guides/get-started/upgrade.md +78 -0
  27. package/{zh/tutorials/first-app → en/docusaurus-plugin-content-docs/current/guides}/overview.md +4 -4
  28. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/_category_.json +4 -0
  29. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/framework-plugin/lifecycle.md +15 -0
  30. package/en/docusaurus-plugin-content-docs/current/tutorials/foundations/introduction.md +1 -1
  31. package/en/docusaurus-plugin-content-docs/current.json +11 -11
  32. package/package.json +4 -4
  33. package/zh/apis/app/commands/dev.md +9 -4
  34. package/zh/apis/app/commands/inspect.md +32 -11
  35. package/zh/apis/app/commands/new.md +1 -1
  36. package/zh/apis/app/commands/{start.md → serve.md} +3 -3
  37. package/zh/apis/app/hooks/src/index_.md +5 -4
  38. package/zh/apis/app/hooks/src/server.md +31 -0
  39. package/zh/apis/app/runtime/core/bootstrap.md +3 -4
  40. package/zh/apis/app/runtime/core/create-app.md +1 -18
  41. package/zh/apis/app/runtime/core/use-module-apps.md +64 -33
  42. package/zh/apis/app/runtime/web-server/hook.md +1 -1
  43. package/zh/apis/app/runtime/web-server/middleware.md +1 -0
  44. package/zh/components/debug-app.md +18 -0
  45. package/zh/components/default-mwa-generate.md +5 -0
  46. package/zh/components/deploy.md +1 -0
  47. package/zh/components/enable-micro-frontend.md +13 -0
  48. package/zh/components/global-proxy.md +28 -0
  49. package/zh/components/init-app.md +44 -0
  50. package/zh/components/micro-runtime-config.md +18 -0
  51. package/zh/components/prerequisites.md +19 -0
  52. package/zh/components/release-note.md +1 -0
  53. package/zh/configure/app/builder-plugins.md +72 -0
  54. package/zh/configure/app/deploy/_category_.json +4 -0
  55. package/zh/configure/app/deploy/microFrontend.md +64 -0
  56. package/zh/configure/app/dev/with-master-app.md +0 -2
  57. package/zh/configure/app/plugins.md +10 -4
  58. package/zh/configure/app/runtime/master-app.md +33 -36
  59. package/zh/configure/app/server/routes.md +2 -4
  60. package/zh/configure/app/source/disable-entry-dirs.md +37 -0
  61. package/zh/configure/app/source/entries-dir.md +0 -3
  62. package/zh/configure/app/source/entries.md +66 -3
  63. package/zh/configure/app/tools/esbuild.md +16 -39
  64. package/zh/guides/advanced-features/bff/bff-proxy.md +1 -1
  65. package/zh/guides/advanced-features/compatibility.md +14 -39
  66. package/zh/guides/advanced-features/eslint.md +21 -21
  67. package/zh/guides/advanced-features/ssg.md +20 -9
  68. package/zh/guides/advanced-features/ssr.md +95 -52
  69. package/zh/guides/advanced-features/testing.md +44 -1
  70. package/zh/guides/advanced-features/web-server.md +14 -3
  71. package/zh/guides/basic-features/css/tailwindcss.md +13 -6
  72. package/zh/guides/basic-features/data-fetch.md +398 -5
  73. package/zh/guides/basic-features/html.md +182 -0
  74. package/zh/guides/basic-features/mock.md +3 -9
  75. package/zh/guides/basic-features/proxy.md +2 -27
  76. package/zh/guides/basic-features/routes.md +35 -3
  77. package/zh/guides/concept/entries.md +108 -19
  78. package/zh/guides/get-started/quick-start.md +14 -83
  79. package/zh/guides/get-started/upgrade.md +11 -9
  80. package/zh/guides/{concept → topic-detail/framework-plugin}/lifecycle.md +0 -0
  81. package/zh/guides/topic-detail/micro-frontend/c01-introduction.md +29 -0
  82. package/zh/guides/topic-detail/micro-frontend/c02-development.md +191 -0
  83. package/zh/guides/topic-detail/micro-frontend/c03-main-app.md +246 -0
  84. package/zh/guides/topic-detail/micro-frontend/c04-communicate.md +54 -0
  85. package/zh/guides/topic-detail/micro-frontend/{mixed-stack.md → c05-mixed-stack.md} +3 -3
  86. package/zh/guides/topic-detail/model/quick-start.md +1 -1
  87. package/zh/guides/topic-detail/model/test-model.md +2 -2
  88. package/zh/guides/topic-detail/monorepo/create-sub-project.md +2 -2
  89. package/zh/guides/topic-detail/monorepo/intro.md +1 -1
  90. package/zh/guides/troubleshooting/dependencies.md +0 -69
  91. package/zh/tutorials/first-app/_category_.json +1 -1
  92. package/zh/tutorials/first-app/c01-start.md +99 -0
  93. package/zh/tutorials/first-app/{c05-component/5.1-use-ui-library.md → c02-component.md} +13 -15
  94. package/zh/tutorials/first-app/c03-css.md +324 -0
  95. package/zh/tutorials/first-app/{c08-client-side-routing/8.1-code-based-routing.md → c04-routes.md} +52 -39
  96. package/zh/tutorials/first-app/c05-loader.md +82 -0
  97. package/zh/tutorials/first-app/c06-model.md +256 -0
  98. package/zh/tutorials/first-app/c07-container.md +283 -0
  99. package/zh/tutorials/first-app/c08-entries.md +137 -0
  100. package/zh/tutorials/foundations/introduction.md +1 -1
  101. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +0 -32
  102. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-modern-mode.md +0 -34
  103. package/zh/apis/generator/overview.md +0 -32
  104. package/zh/configure/app/output/enable-modern-mode.md +0 -34
  105. package/zh/guides/advanced-features/custom-app.md +0 -72
  106. package/zh/guides/topic-detail/micro-frontend/communicate.md +0 -39
  107. package/zh/guides/topic-detail/micro-frontend/debugging.md +0 -168
  108. package/zh/guides/topic-detail/micro-frontend/introduction.md +0 -13
  109. package/zh/guides/topic-detail/micro-frontend/route-mode.md +0 -110
  110. package/zh/guides/topic-detail/monorepo/deploy.md +0 -43
  111. package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +0 -25
  112. package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +0 -118
  113. package/zh/tutorials/first-app/c01-getting-started/1.3-dev-command.md +0 -29
  114. package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +0 -47
  115. package/zh/tutorials/first-app/c01-getting-started/1.5-start-command.md +0 -18
  116. package/zh/tutorials/first-app/c01-getting-started/1.6-create-repo.md +0 -31
  117. package/zh/tutorials/first-app/c01-getting-started/_category_.json +0 -3
  118. package/zh/tutorials/first-app/c02-generator-and-studio/2.1-generator.md +0 -79
  119. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +0 -34
  120. package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +0 -19
  121. package/zh/tutorials/first-app/c02-generator-and-studio/_category_.json +0 -3
  122. package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +0 -55
  123. package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +0 -60
  124. package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +0 -11
  125. package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +0 -63
  126. package/zh/tutorials/first-app/c03-ide/_category_.json +0 -3
  127. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +0 -54
  128. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +0 -135
  129. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.3-compatibility.md +0 -67
  130. package/zh/tutorials/first-app/c04-es6-plus-and-ts/_category_.json +0 -3
  131. package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +0 -72
  132. package/zh/tutorials/first-app/c05-component/_category_.json +0 -3
  133. package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +0 -110
  134. package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +0 -143
  135. package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +0 -84
  136. package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +0 -83
  137. package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +0 -77
  138. package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +0 -104
  139. package/zh/tutorials/first-app/c06-css-and-component/_category_.json +0 -3
  140. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +0 -69
  141. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +0 -100
  142. package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +0 -69
  143. package/zh/tutorials/first-app/c07-app-entry/_category_.json +0 -3
  144. package/zh/tutorials/first-app/c08-client-side-routing/_category_.json +0 -3
  145. package/zh/tutorials/first-app/c09-bff/9.1-serverless.md +0 -30
  146. package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +0 -95
  147. package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +0 -131
  148. package/zh/tutorials/first-app/c09-bff/_category_.json +0 -3
  149. package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +0 -21
  150. package/zh/tutorials/first-app/c10-model/10.2-add-model.md +0 -185
  151. package/zh/tutorials/first-app/c10-model/10.3-use-model.md +0 -55
  152. package/zh/tutorials/first-app/c10-model/10.4-testing.md +0 -69
  153. package/zh/tutorials/first-app/c10-model/_category_.json +0 -3
  154. package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +0 -240
  155. package/zh/tutorials/first-app/c11-container/11.2-add-container.md +0 -109
  156. package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +0 -63
  157. package/zh/tutorials/first-app/c11-container/11.4-testing.md +0 -56
  158. package/zh/tutorials/first-app/c11-container/_category_.json +0 -3
@@ -1,32 +0,0 @@
1
- ---
2
- sidebar_position: 6
3
- ---
4
-
5
- ```bash
6
- Usage: modern start [options]
7
-
8
- start server
9
-
10
- Options:
11
- -c --config <config> configuration file path, which can be a relative path or an absolute path
12
- -h, --help show command help
13
- --api-only only start API service
14
- ```
15
-
16
- Usually use the `modern start` command to enable project start in the production environment, and you need to execute the [`build'](/docs/apis/app/commands/build) command in advance to build the product.
17
-
18
- By default, the project will start in `localhost:8080`, you can modify the Server port number with `server.port`:
19
-
20
- ```js
21
- export default defineConfig({
22
- server: {
23
- port: 8081,
24
- }
25
- })
26
- ```
27
-
28
- import CommandTip from '@site-docs-en/components/command-tip.md'
29
-
30
- <CommandTip />
31
-
32
-
@@ -1,34 +0,0 @@
1
- ---
2
- sidebar_label: enableModernMode
3
- ---
4
-
5
- # output.enableModernMode
6
-
7
- * Type: `boolean`
8
- * Default: `false`
9
-
10
- Modern.js default value to build JS products with Polyfill for older browsers. After opening this configuration, you can automatically build JS products that are not degraded for modern browser syntax in the production environment. The product filename format is `[name].[hash]-es6/js`.
11
-
12
- For example, configure the following configuration:
13
-
14
- ```ts title="modern.config.ts"
15
- import { defineConfig } from '@modern-js/app-tools';
16
-
17
- export default defineConfig({
18
- output: {
19
- enableModernMode: true,
20
- },
21
- });
22
- ```
23
-
24
- After executing the `build` command, modern is packaged in addition to the normal Client packaging, and the `dist/static/js` directory will generate es6 related products.
25
-
26
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/output-enable-modern-build.jpeg)
27
-
28
- After executing the `start` command, use the latest version Chrome browser access, and observe that the requested JS resource in the Network is an es6 product.
29
-
30
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/output-enable-modern-network.jpeg)
31
-
32
- :::info
33
- For more information, see [Client side compatibility](/docs/guides/advanced-features/compatibility)。
34
- :::
@@ -1,32 +0,0 @@
1
- ---
2
- sidebar_position: 0
3
- ---
4
-
5
- # 概览
6
- Modern.js 提供了 `create` 工具用于初始化不同工程方案项目。
7
-
8
- ## 基本使用
9
-
10
- ```bash
11
- npx @modern-js/create [projectDir]
12
- ```
13
-
14
- ```bash
15
- Usage: create [projectDir]
16
-
17
- 创建 @modern-js 应用
18
-
19
- Options:
20
- -c, --config <config> 创建项目默认配置(JSON 字符串) (default: "{}")
21
- --mwa 一键创建应用工程(使用默认配置) (default: false)
22
- --module 一键创建模块工程(使用默认配置) (default: false)
23
- --monorepo 一键常见 Monorepo 应用(使用默认配置) (default: false)
24
- --dist-tag <distTag> 生成项目时生成器使用特殊的 npm Tag (default: "")
25
- --registry <registry> 在创建过程中定制 npm Registry (default: "")
26
- -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)
27
- -h, --help display help for command
28
- ```
29
-
30
- :::info 补充信息
31
- 不需要全局安装 `@modern-js/create`,使用 npx 按需运行即可,可以保证始终运行最新版本的项目生成器。
32
- :::
@@ -1,34 +0,0 @@
1
- ---
2
- sidebar_label: enableModernMode
3
- ---
4
-
5
- # output.enableModernMode
6
-
7
- * 类型: `boolean`
8
- * 默认值:`false`
9
-
10
- Modern.js 默认值构建针对旧版浏览器带有 Polyfill 的 JS 产物,开启该配置后,可以在生产环境会自动构建出针对现代浏览器语法未降级的 JS 产物,产物文件名格式为 `[name].[hash]-es6/js`。
11
-
12
- 例如配置如下配置:
13
-
14
- ```ts title="modern.config.ts"
15
- import { defineConfig } from '@modern-js/app-tools';
16
-
17
- export default defineConfig({
18
- output: {
19
- enableModernMode: true,
20
- },
21
- });
22
- ```
23
-
24
- 执行 `build` 命令后,除了正常的 Client 打包外, 还进行了 Modern 的打包,并且 `dist/static/js` 目录会生成 es6 相关产物。
25
-
26
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/output-enable-modern-build.jpeg)
27
-
28
- 执行 `start` 命令后,使用最新版本 Chrome 浏览器访问,观察 Network 中请求的 JS 资源为 es6 产物。
29
-
30
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/output-enable-modern-network.jpeg)
31
-
32
- :::info
33
- 更多内容可以查看[客户端兼容性](/docs/guides/advanced-features/compatibility)。
34
- :::
@@ -1,72 +0,0 @@
1
- ---
2
- title: 自定义 App
3
- sidebar_position: 7
4
- ---
5
-
6
- 在[入口](/docs/guides/concept/entries)概念中提到, Modern.js 提供了三种文件约定来标记入口。
7
-
8
- 通常情况下,`routes/` 与 `App.[jt]sx` 两种模式已经能够满足需求。当开发者需要在根组件挂载前做些操作,或者完全接管 Webpack 入口时,可以在入口目录下放置 `index.[jt]sx` 文件,我们称为**自定义 App**。
9
-
10
- ## 添加自定义行为
11
-
12
- 当 `index` 文件默认导出**函数**是,Modern.js 还是会根据 `runtime` 的设置情况生成 `createApp` 包裹后的代码。在渲染过程中,将 `createApp` 包裹后的组件作为参数传递给 `index` 文件导出的函数,这样开发者可以自定义将组件挂载到 DOM 节点上,或在挂载前添加自定义行为。例如:
13
-
14
- ```js title=src/index.jsx
15
- import ReactDOM from 'react-dom/client'
16
- import { bootstrap } from '@modern-js/runtime';
17
-
18
-
19
- export default App => {
20
- // do something before bootstrap...
21
- bootstrap(App, 'root', undefined, ReactDOM);
22
- };
23
- ```
24
-
25
- :::warning
26
- 由于 bootstrap 函数需要兼容 React17 和 React18 的用法,调用 bootstrap 函数时需要手动传入 ReactDOM 参数。
27
- :::
28
-
29
- Modern.js 生成的文件内容如下:
30
-
31
- ```js
32
- import customRender from '@/src/index.js';
33
- import { createApp, bootstrap } from '@modern-js/runtime';
34
- import React from 'react';
35
- import App from '@/src/App';
36
-
37
- const IS_BROWSER = typeof window !== 'undefined';
38
- const MOUNT_ID = 'root';
39
-
40
- let AppWrapper = null;
41
-
42
- const renderApp = () => {
43
- AppWrapper = createApp({
44
- // runtime 的插件参数...
45
- })(App);
46
- customRender(AppWrapper);
47
- };
48
-
49
- renderApp();
50
-
51
- export default AppWrapper;
52
-
53
- if (IS_BROWSER && module.hot) {
54
- module.hot.accept('<path>/src/App', () => {
55
- renderApp();
56
- });
57
- }
58
- ```
59
-
60
- ## 完全接管 Webpack 入口
61
-
62
- 当 `index.[jt]sx` 文件没有导出函数时,这时候该文件就是真正的 Webpack 入口文件。这里和 [Create React App](https://github.com/facebook/create-react-app) 类似,需要自己将组件挂载到 DOM 节点、添加热更新代码等。例如:
63
-
64
- ```js title=src/index.jsx
65
- import React from 'react';
66
- import ReactDOM from 'react-dom';
67
- import App from './App';
68
-
69
- ReactDOM.render(<App />, document.getElementById('root'));
70
- ```
71
-
72
- Modern.js **不推荐**使用这种方式,这种方式丧失了框架的一些能力,如 **`modern.config.js` 文件中的 `runtime` 配置将不会再生效**。
@@ -1,39 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- title: 主子应用通信
4
- ---
5
-
6
- ## props 通信
7
-
8
- Modern.js 中,会将子应用包裹成一个 React 组件,直接通过给 React 组件传递 `props` 即可实现主应用和子应用通信的目的。
9
-
10
- ```tsx title=主应用:App.tsx
11
- function App() {
12
- const { Dashboard } = useModuleApps();
13
- const [count, setCount] = useState(0);
14
-
15
- return <div>
16
- <Dashboard count={count} />
17
- <button onClick={() => setCount(count + 1)}>add</button>
18
- </div>;
19
- }
20
- ```
21
-
22
- ```tsx title=子应用:App.tsx
23
- function App(props) {
24
- console.log(props);
25
-
26
- return ...
27
- }
28
- ```
29
-
30
- 子应用将会打印 `{count: 0}`。
31
-
32
- 当主应用点击 `add` 按钮,`count` 状态更新的时候,子应用也会响应到最新的 `props` 数据,并重新渲染。
33
-
34
- ## 使用 Model 通信
35
-
36
-
37
- :::tip 提示
38
- 近期上线,敬请期待。
39
- :::
@@ -1,168 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- title: 子应用调试
4
- ---
5
-
6
- 根据研发的不同阶段,我们将子应用调试分为如下两种方式:
7
-
8
- 1. 使用本地主应用调试。
9
- 2. 使用线上主应用调试。
10
-
11
- ## 使用本地主应用调试
12
-
13
- 项目初期,主应用未部署,可以使用本地分别启动主应用、子应用的方式进行调试。
14
-
15
- ### 主应用
16
-
17
- #### 配置
18
-
19
- ```typescript title="modern.config.ts"
20
- export default defineConfig({
21
- runtime: {
22
- router: true,
23
- masterApp: {
24
- manifest: {
25
- modules: [
26
- {
27
- name: 'Dashboard',
28
- entry: 'http://localhost:8081',
29
- },
30
- ],
31
- },
32
- },
33
- },
34
- });
35
- ```
36
-
37
- 假设本地的子应用的名字为 `DashBoard` 且启动服务的地址为 `http://localhost:8081`。配置 `runtime.masterApp.modules` 字段指定子应用的相关信息。
38
-
39
- #### 加载子应用
40
-
41
- 使用 [useModuleApps](/docs/apis/app/runtime/core/use-module-apps) API 获取子应用组件,并加载子应用。
42
-
43
- ```tsx title=App.tsx
44
- import { useModuleApps } from '@modern-js/plugin-garfish';
45
-
46
- function App() {
47
- const { Dashboard } = useModuleApps();
48
-
49
- return (
50
- <div>
51
- Master APP
52
- <Route path="/dashboard">
53
- <Dashboard />
54
- </Route>
55
- </div>
56
- );
57
- }
58
- ```
59
-
60
- ### 子应用
61
-
62
- #### 配置
63
-
64
- ```typescript title="modern.config.ts"
65
- export default defineConfig({
66
- deploy: {
67
- microFrontend: true,
68
- },
69
- });
70
- ```
71
-
72
- 当 `deploy.microFrontend` 字段配置为 true 的时候,Modern.js 将认为当前应用是一个微前端子应用,并将其编译为符合 Garfish 子应用规范的产物。
73
-
74
- #### 子应用代码
75
-
76
- 子应用在代码层面和应用工程是完全一致的。
77
-
78
- ```tsx title=src/App.tsx
79
- function App() {
80
- return <div>dashboard</div>;
81
- }
82
- ```
83
-
84
- :::info 注
85
- 目前不支持在子应用中使用 BFF 功能。
86
- :::
87
-
88
- 然后分别启动主应用和子应用(执行 `pnpm dev`),主应用访问 `8080` 端口,子应用访问 `8081` 端口。浏览器打开 `http://localhost:8080/dashboard` 就能看到加载了 `Dashboard` 子应用的效果了。
89
-
90
- ## 使用线上主应用调试
91
-
92
- 当主应用项目部署之后,Modern.js 提供了用线上主应用调试本地子应用的方式。
93
-
94
- :::info 注
95
- 本小节所用线上地址均是虚构,只为演示方便。
96
- :::
97
-
98
- ### 主应用
99
-
100
- #### 配置
101
-
102
- ```typescript title="modern.config.ts"
103
- export default defineConfig({
104
- server: {
105
- enableMicroFrontendDebug: true,
106
- },
107
- runtime: {
108
- router: true,
109
- masterApp: {
110
- manifest: {
111
- modules: [
112
- {
113
- name: 'Dashboard',
114
- entry: 'http://modern-js.dev/dashboard',
115
- },
116
- ],
117
- },
118
- },
119
- },
120
- });
121
- ```
122
-
123
- :::info 注
124
- `enableMicroFrontendDebug` 会在线上开启 微前端 Debug 模式,如担心安全隐患,可只在线上测试环境开启,线上正式环境关掉该配置。
125
- :::
126
-
127
- ### 子应用
128
-
129
- #### 配置
130
-
131
- ```typescript title="modern.config.ts"
132
- export default defineConfig({
133
- deploy: {
134
- microFrontend: true,
135
- },
136
- });
137
- ```
138
-
139
- 本地启动子应用,其端口为 `8080`。
140
-
141
- ### Query 模式调试
142
-
143
- 访问主应用地址 `http://master.example.com/` 并在 URL 后加上 Query `?__debug__micro-frontend-debug-name=TableList&__debug__micro-frontend-debug-entry=http://localhost:8080`。
144
-
145
- 此时访问主应用后,服务端注入的子应用模块信息将被替换为我们 Query 里的信息。即 `TableList` 子应用 `entry` 为 `http://localhost:8080`。线上主应用切换到 `/tablelist` 路由后将会加载本地的子应用。
146
-
147
- ![query-debug](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/query-debug.png)
148
-
149
- ### Header 模式调试(推荐)
150
-
151
- Query 调试时,当路透跳转的时候,Query 参数会丢失,reload 页面后,服务端返回的子应用信息里将不会注入本地的子应用信息。可以使用 Header 模式来调试,获取更稳定的调试开发体验。
152
-
153
- #### 环境要求
154
-
155
- [ModHeader](https://modheader.com/install) 是用于 Mock 浏览器请求/返回 Header 的浏览器插件。使用 ModHeader 支持的浏览器(Chrome、Firefox、Opera、Edge),并安装 ModHeader 插件。
156
-
157
- #### 配置 Header
158
-
159
- 配置如下 Header:
160
-
161
- - `x-micro-frontend-module-name TableList`
162
- - `x-micro-frontend-module-entry http://localhost:8080`
163
-
164
- 访问主应用地址如下所示
165
-
166
- ![header-debug](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/header-debug.png)
167
-
168
- 可以看到此时服务端返回的 `TableList` 子应用信息是 Header 里面指定的本地域名 `http://localhost:8080`
@@ -1,13 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- title: 微前端介绍
4
- ---
5
-
6
- 随着前端生态的繁重以及 Web 应用日益复杂化,给大型项目研发流程、跨团队协作等带来不小的挑战。微前端从架构层面出发将多个独立交付的前端应用组成整体,这些前端应用能够「独立开发」、「独立测试」、「独立部署」,但是最终在用户看来仍然是内聚的单个产品。
7
-
8
- [Garfish](https://garfish.top/guide/) 是业界成熟的微前端解决方案,Modern.js 中开箱即用的支持了 [Garfish](https://garfish.top/guide/)。
9
-
10
- 在微前端研发模式中,应用会被分成 **主应用**、和 **子应用**。
11
-
12
- - 主应用:微前端项目的基座工程,所有子应用都会由它来加载。
13
- - 子应用:独立开发、独立部署的应用,最终会被主应用加载。
@@ -1,110 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- title: 加载子应用
4
- ---
5
-
6
- 在微前端中分为两种加载子应用的方式:
7
-
8
- 1. **子应用组件** 获取到每个子应用的组件,之后就可以像使用普通的 React 组件一样渲染微前端的子应用。
9
- 2. **集中式路由** 通过集中式的路由配置,自动根据当前页面 pathname 激活渲染对应的子应用。
10
-
11
- ## 子应用组件
12
-
13
- 使用 `useModuleApps` API 可以获取到各个子应用的组件。结合 `router`,可以自控式的根据不同的路由渲染不同的子应用。
14
-
15
- 假设我们的子应用列表配置如下:
16
-
17
- ```typescript title="modern.config.ts"
18
- export default defineConfig({
19
- runtime: {
20
- masterApp: {
21
- manifest: {
22
- modules: [
23
- {
24
- name: "Dashboard",
25
- entry: "http://localhost:8081"
26
- },
27
- {
28
- name: "TableList",
29
- entry: "http://localhost:8082"
30
- }
31
- ]
32
- }
33
- }
34
- }
35
- }
36
- ```
37
-
38
- 编辑主应用 `App.tsx` 文件如下:
39
-
40
- ```tsx title=主应用:App.tsx
41
- import { useModuleApps } from '@modern-js/plugin-garfish';
42
- import { Route, Switch } from '@modern-js/runtime/router';
43
-
44
- function App() {
45
- const { Dashboard, TableList } = useModuleApps();
46
-
47
- return <div>
48
- <Switch>
49
- <Route path='/dashboard'>
50
- <Dashboard />
51
- </Route>
52
- <Route path='/tablelist'>
53
- <TableList />
54
- </Route>
55
- </ Switch>
56
- </div>
57
- }
58
- ```
59
-
60
- 这里通过 `Route` 组件自定义了 **DashBoard** 的激活路由为 **/dashboard**, **TableList** 的激活路由为 **/tablelist**。
61
-
62
- ## 集中式路由
63
-
64
- **集中式路由** 是将子应用的激活路由集中配置的方式。我们给子应用列表信息添加 `activeWhen` 字段来启用 **集中式路由**。
65
-
66
- ```typescript title="modern.config.ts"Å {8,13}
67
- export default defineConfig({
68
- runtime: {
69
- masterApp: {
70
- manifest: {
71
- modules: [
72
- {
73
- name: "Dashboard",
74
- activeWhen: '/dashboard',
75
- entry: "http://localhost:8081"
76
- },
77
- {
78
- name: TableList,
79
- activeWhen: '/tablelist',
80
- entry: "http://localhost:8082"
81
- }
82
- ]
83
- }
84
- }
85
- }
86
- }
87
- ```
88
-
89
- 然后在主应用中使用 `useModuleApp` API 来获取 `MApp` 在主应用渲染。
90
-
91
- ```tsx title=主应用:App.tsx
92
- import { useModuleApp } from '@modern-js/runtime';
93
-
94
- function App() {
95
- const MApp = useModuleApp();
96
-
97
- return <div>
98
- <MApp />
99
- </div>
100
- }
101
- ```
102
-
103
- 这样启动应用后,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用,访问 `/tablelist` 路由,会渲染 `TableList` 子应用。
104
-
105
- ## 两种模式混用
106
-
107
- 当然 **子应用组件** 和 **集中式路由** 是可以混合使用的。
108
-
109
- - 一部分子应用作为 **子应用组件** 激活,另外一部分作为 **集中式路由** 激活。
110
- - 一部分子应用既可以作为 **集中式路由** 激活,也可以作为 **子应用组件** 激活。
@@ -1,43 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
-
5
- # 应用项目的部署
6
-
7
- 本章将要介绍如何在 Monorepo 中对应用项目进行部署。
8
-
9
- 所谓的 “在 Monorepo 中对应用项目进行部署” 更像是应用项目部署到服务器的前置工作。应用项目的功能一般来自以下部分
10
-
11
- - 自身的代码逻辑功能
12
- - 第三方的依赖
13
- - Monorepo 中其他子项目提供的逻辑功能
14
-
15
- 而在将应用项目放到部署服务器之前,需要对应用项目、第三方依赖以及它所依赖的子项目做整合处理。
16
-
17
- Modern.js 为 Monorepo 工程提供了部署功能,该功能可以为要部署的项目生成一个最小集合的 Monorepo,在这个 Monorepo 当中包含应用项目以及其依赖的子项目。
18
-
19
- 我们以 [子项目联调](/docs/guides/topic-detail/monorepo/sub-project-interface) 章节的例子为例,如果要发布 `apps/app` 应用项目,那么在 Monorepo 根目录下执行:
20
-
21
- ```
22
- pnpm deploy app
23
- ```
24
-
25
- :::info 补充信息
26
- `app` 为应用项目的项目名称,或者说是 `package.json` 的 `name` 对应的值。
27
- :::
28
-
29
- 执行命令之后,首先会在 Monorepo 根目录下生成 `output` 目录,其中包含了应用项目 `apps/app`、`features/internal-lib`、`packages/components`。
30
-
31
- :::info 补充信息
32
- `output` 目录就是需要部署到服务器上的目录,可以通过命令参数进行路径修改。可以查看 [deploy 命令](/docs/apis/monorepo/commands/deploy)。
33
- :::
34
-
35
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/guides/monorepo-output.png)
36
-
37
- 然后会自动进行依赖的安装。
38
-
39
- 最后当 deploy 命令运行完成后,我们可以将 `output` 放到部署项目的服务器上。
40
-
41
- :::tip 提示
42
- 在使用 Yarn 的 Monorepo 中,推荐全局安装 [Lerna](https://github.com/lerna/lerna) 作为 Monorepo 子项目额外的管理工具。由于 [Yarn 1 (Classic) ](https://classic.yarnpkg.com/lang/en/) 在安装依赖的时候,不会触发子项目的 [Life Cycle Scripts](https:/docs.npmjs.com/cli/v7/using-npm/scripts#life-cycle-scripts),因此还需要使用 Lerna 完成这类事情。
43
- :::
@@ -1,25 +0,0 @@
1
- ---
2
- title: 环境准备
3
- ---
4
-
5
- 从本章节开始,我们将进入实战教程部分。
6
-
7
- 在实战教程中,我们将会从环境准备开始,从简单到复杂,一步一步搭建一个真实的项目。
8
-
9
- 基于 Modern.js 框架的项目,自带全套工程环境和工程能力,对仓库目录之外的环境几乎没有任何依赖,只需要安装以下少数几个最基本的工具。
10
-
11
- ## 1. Node.js
12
-
13
- 需要 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 14.19.0, 推荐使用 16.x 版本。
14
-
15
- Modern.js 推荐在开发环境里先安装 [nvm](https://github.com/nvm-sh/nvm#install--update-script),在 shell 里集成[自动切换 node 版本的脚本](https://github.com/nvm-sh/nvm#deeper-shell-integration)。
16
-
17
- 然后只要仓库根目录下有内容为 `lts/fermium` 或 `lts/gallium` 的 `.nvmrc` 文件,进入这个仓库时就会自动安装或切换到正确的 Node.js 版本。
18
-
19
- ## 2. pnpm
20
-
21
- 推荐使用 [pnpm](https://pnpm.io/installation) 来管理项目依赖:
22
-
23
- ```bash
24
- npm install -g pnpm
25
- ```