@modern-js/main-doc 2.4.0 → 2.5.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/.turbo/turbo-build.log +1 -1
- package/LICENSE +0 -123
- package/README.md +26 -0
- package/en/apis/app/commands/_category_.json +1 -4
- package/en/apis/app/commands/new.mdx +11 -10
- package/en/apis/app/commands/test.mdx +1 -1
- package/en/apis/app/hooks/_category_.json +1 -4
- package/en/apis/app/hooks/api/framework/lambda.mdx +1 -1
- package/en/apis/app/hooks/api/functions/api.mdx +1 -1
- package/en/apis/app/hooks/server/index_.mdx +2 -1
- package/en/apis/app/hooks/src/pages.mdx +7 -7
- package/en/apis/app/hooks/src/routes.mdx +1 -1
- package/en/apis/app/runtime/_category_.json +1 -5
- package/en/apis/app/runtime/app/define-config.mdx +2 -2
- package/en/apis/app/runtime/core/bootstrap.mdx +1 -1
- package/en/apis/app/runtime/core/create-app.mdx +2 -2
- package/en/apis/app/runtime/core/use-loader.mdx +4 -4
- package/en/apis/app/runtime/core/use-module-apps.mdx +2 -2
- package/en/apis/app/runtime/model/Provider.mdx +2 -2
- package/en/apis/app/runtime/model/auto-actions.mdx +2 -2
- package/en/apis/app/runtime/model/connect.mdx +5 -5
- package/en/apis/app/runtime/model/create-app.mdx +9 -9
- package/en/apis/app/runtime/model/create-store.mdx +3 -3
- package/en/apis/app/runtime/model/handle-effect.mdx +2 -2
- package/en/apis/app/runtime/model/model_.mdx +1 -1
- package/en/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-model.mdx +1 -1
- package/en/apis/app/runtime/model/use-static-model.mdx +4 -4
- package/en/apis/app/runtime/model/use-store.mdx +1 -1
- package/en/apis/app/runtime/router/router.mdx +1 -1
- package/en/apis/app/runtime/ssr/pre-render.mdx +1 -1
- package/en/apis/app/runtime/testing/render.mdx +1 -1
- package/en/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/en/apis/app/runtime/utility/css-in-js.mdx +1 -1
- package/en/apis/app/runtime/utility/loadable.mdx +1 -1
- package/en/apis/app/runtime/web-server/hook.mdx +5 -5
- package/en/apis/app/runtime/web-server/middleware.mdx +6 -6
- package/en/components/global-proxy-config.mdx +3 -3
- package/en/configure/app/bff/_category_.json +4 -0
- package/en/configure/app/builder-plugins.mdx +3 -3
- package/en/configure/app/deploy/_category_.json +4 -0
- package/en/configure/app/dev/_category_.json +4 -0
- package/en/configure/app/dev/asset-prefix.mdx +1 -1
- package/en/configure/app/dev/hmr.mdx +1 -1
- package/en/configure/app/dev/https.mdx +1 -1
- package/en/configure/app/dev/port.mdx +1 -1
- package/en/configure/app/dev/progress-bar.mdx +1 -1
- package/en/configure/app/dev/start-url.mdx +1 -1
- package/en/configure/app/experiments/_category_.json +4 -0
- package/en/configure/app/experiments/lazy-compilation.mdx +1 -1
- package/en/configure/app/html/_category_.json +4 -0
- package/en/configure/app/html/app-icon.mdx +1 -1
- package/en/configure/app/html/crossorigin.mdx +1 -1
- package/en/configure/app/html/disable-html-folder.mdx +1 -1
- package/en/configure/app/html/favicon-by-entries.mdx +1 -1
- package/en/configure/app/html/favicon.mdx +1 -1
- package/en/configure/app/html/inject-by-entries.mdx +1 -1
- package/en/configure/app/html/inject.mdx +1 -1
- package/en/configure/app/html/meta-by-entries.mdx +1 -1
- package/en/configure/app/html/meta.mdx +1 -1
- package/en/configure/app/html/mount-id.mdx +1 -1
- package/en/configure/app/html/tags-by-entries.mdx +1 -1
- package/en/configure/app/html/tags.mdx +1 -1
- package/en/configure/app/html/template-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters-by-entries.mdx +1 -1
- package/en/configure/app/html/template-parameters.mdx +1 -1
- package/en/configure/app/html/template.mdx +1 -1
- package/en/configure/app/html/title-by-entries.mdx +1 -1
- package/en/configure/app/html/title.mdx +1 -1
- package/en/configure/app/output/_category_.json +4 -0
- package/en/configure/app/output/asset-prefix.mdx +1 -1
- package/en/configure/app/output/assets-retry.mdx +1 -1
- package/en/configure/app/output/charset.mdx +1 -1
- package/en/configure/app/output/clean-dist-path.mdx +1 -1
- package/en/configure/app/output/convert-to-rem.mdx +1 -1
- package/en/configure/app/output/copy.mdx +1 -1
- package/en/configure/app/output/css-module-local-ident-name.mdx +1 -1
- package/en/configure/app/output/data-uri-limit.mdx +1 -1
- package/en/configure/app/output/disable-css-extract.mdx +1 -1
- package/en/configure/app/output/disable-css-module-extension.mdx +1 -1
- package/en/configure/app/output/disable-filename-hash.mdx +1 -1
- package/en/configure/app/output/disable-inline-runtime-chunk.mdx +1 -1
- package/en/configure/app/output/disable-minimize.mdx +1 -1
- package/en/configure/app/output/disable-source-map.mdx +1 -1
- package/en/configure/app/output/disable-ts-checker.mdx +1 -1
- package/en/configure/app/output/dist-path.mdx +1 -1
- package/en/configure/app/output/enable-asset-fallback.mdx +1 -1
- package/en/configure/app/output/enable-asset-manifest.mdx +1 -1
- package/en/configure/app/output/enable-css-module-tsdeclaration.mdx +1 -1
- package/en/configure/app/output/enable-inline-scripts.mdx +1 -1
- package/en/configure/app/output/enable-inline-styles.mdx +1 -1
- package/en/configure/app/output/enable-latest-decorators.mdx +1 -1
- package/en/configure/app/output/externals.mdx +1 -1
- package/en/configure/app/output/filename.mdx +1 -1
- package/en/configure/app/output/legal-comments.mdx +1 -1
- package/en/configure/app/output/override-browserslist.mdx +1 -1
- package/en/configure/app/output/polyfill.mdx +1 -1
- package/en/configure/app/output/ssg.mdx +2 -2
- package/en/configure/app/output/svg-default-export.mdx +1 -1
- package/en/configure/app/performance/_category_.json +4 -0
- package/en/configure/app/performance/build-cache.mdx +1 -1
- package/en/configure/app/performance/bundle-analyze.mdx +1 -1
- package/en/configure/app/performance/chunk-split.mdx +1 -1
- package/en/configure/app/performance/print-file-size.mdx +1 -1
- package/en/configure/app/performance/profile.mdx +1 -1
- package/en/configure/app/performance/remove-console.mdx +1 -1
- package/en/configure/app/performance/remove-moment-locale.mdx +1 -1
- package/en/configure/app/plugins.mdx +1 -1
- package/en/configure/app/runtime/_category_.json +4 -0
- package/en/configure/app/runtime/intro.mdx +2 -2
- package/en/configure/app/security/_category_.json +4 -0
- package/en/configure/app/security/check-syntax.mdx +1 -1
- package/en/configure/app/security/sri.mdx +1 -1
- package/en/configure/app/server/_category_.json +4 -0
- package/en/configure/app/server/base-url.mdx +3 -3
- package/en/configure/app/server/enable-framework-ext.mdx +1 -1
- package/en/configure/app/server/ssr-by-entries.mdx +1 -1
- package/en/configure/app/source/_category_.json +4 -0
- package/en/configure/app/source/alias.mdx +1 -1
- package/en/configure/app/source/compile-js-data-uri.mdx +1 -1
- package/en/configure/app/source/define.mdx +1 -1
- package/en/configure/app/source/design-system.mdx +5 -5
- package/en/configure/app/source/entries.mdx +3 -3
- package/en/configure/app/source/exclude.mdx +1 -1
- package/en/configure/app/source/global-vars.mdx +1 -1
- package/en/configure/app/source/include.mdx +1 -1
- package/en/configure/app/source/module-scopes.mdx +1 -1
- package/en/configure/app/source/pre-entry.mdx +1 -1
- package/en/configure/app/source/resolve-extension-prefix.mdx +1 -1
- package/en/configure/app/source/resolve-main-fields.mdx +1 -1
- package/en/configure/app/testing/_category_.json +4 -0
- package/en/configure/app/tools/_category_.json +4 -0
- package/en/configure/app/tools/autoprefixer.mdx +1 -1
- package/en/configure/app/tools/babel.mdx +1 -1
- package/en/configure/app/tools/css-extract.mdx +1 -1
- package/en/configure/app/tools/css-loader.mdx +1 -1
- package/en/configure/app/tools/dev-server.mdx +1 -1
- package/en/configure/app/tools/html-plugin.mdx +1 -1
- package/en/configure/app/tools/inspector.mdx +1 -1
- package/en/configure/app/tools/less.mdx +1 -1
- package/en/configure/app/tools/minify-css.mdx +1 -1
- package/en/configure/app/tools/postcss.mdx +1 -1
- package/en/configure/app/tools/pug.mdx +1 -1
- package/en/configure/app/tools/rspack.mdx +13 -0
- package/en/configure/app/tools/sass.mdx +1 -1
- package/en/configure/app/tools/style-loader.mdx +1 -1
- package/en/configure/app/tools/styled-components.mdx +1 -1
- package/en/configure/app/tools/tailwindcss.mdx +1 -1
- package/en/configure/app/tools/terser.mdx +1 -1
- package/en/configure/app/tools/ts-checker.mdx +1 -1
- package/en/configure/app/tools/ts-loader.mdx +1 -1
- package/en/configure/app/tools/webpack-chain.mdx +1 -1
- package/en/configure/app/tools/webpack.mdx +1 -1
- package/en/configure/app/usage.mdx +1 -1
- package/en/guides/advanced-features/_category_.json +2 -2
- package/en/guides/advanced-features/bff/bff-proxy.mdx +1 -1
- package/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/en/guides/advanced-features/bff/function.mdx +3 -3
- package/en/guides/advanced-features/code-split.mdx +2 -2
- package/en/guides/advanced-features/compatibility.mdx +2 -3
- package/en/guides/advanced-features/eslint.mdx +4 -4
- package/en/guides/advanced-features/low-level.mdx +1 -1
- package/en/guides/advanced-features/ssg.mdx +4 -5
- package/en/guides/advanced-features/ssr.mdx +3 -3
- package/en/guides/advanced-features/testing.mdx +4 -5
- package/en/guides/advanced-features/web-server.mdx +0 -1
- package/en/guides/basic-features/alias.mdx +1 -1
- package/en/guides/basic-features/data-fetch.mdx +21 -8
- package/en/guides/basic-features/env-vars.mdx +1 -1
- package/en/guides/basic-features/html.mdx +11 -11
- package/en/guides/basic-features/mock.mdx +21 -1
- package/en/guides/basic-features/proxy.mdx +2 -2
- package/en/guides/basic-features/routes.mdx +6 -8
- package/en/guides/{basic-features → concept}/builder.mdx +1 -1
- package/en/guides/concept/entries.mdx +11 -11
- package/en/guides/css/_category_.json +5 -0
- package/en/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- package/en/guides/{basic-features/css → css}/css-modules.mdx +0 -0
- package/en/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/en/guides/{basic-features/css → css}/postcss.mdx +0 -0
- package/en/guides/{basic-features/css → css}/tailwindcss.mdx +0 -0
- package/en/guides/get-started/introduction.mdx +34 -0
- package/en/guides/get-started/quick-start.mdx +2 -2
- package/en/guides/get-started/upgrade.mdx +2 -1
- package/en/guides/topic-detail/_category_.json +2 -2
- package/en/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/develop.mdx +1 -1
- package/en/guides/topic-detail/micro-frontend/c02-development.mdx +128 -61
- package/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +72 -41
- package/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
- package/en/guides/topic-detail/model/auto-actions.mdx +1 -1
- package/en/guides/topic-detail/model/define-model.mdx +1 -1
- package/en/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/en/guides/topic-detail/model/quick-start.mdx +2 -2
- package/en/guides/topic-detail/model/test-model.mdx +1 -1
- package/en/guides/topic-detail/model/use-model.mdx +3 -3
- package/en/guides/troubleshooting/_category_.json +2 -2
- package/en/guides/troubleshooting/cli.mdx +1 -1
- package/en/index.md +1 -1
- package/en/tutorials/first-app/_category_.json +1 -1
- package/en/tutorials/first-app/c01-start.mdx +0 -1
- package/en/tutorials/first-app/c03-css.mdx +1 -2
- package/en/tutorials/first-app/c06-model.mdx +1 -1
- package/en/tutorials/first-app/c07-container.mdx +1 -1
- package/en/tutorials/first-app/c08-entries.mdx +1 -2
- package/en/tutorials/foundations/introduction.mdx +17 -34
- package/package.json +3 -3
- package/scripts/config.ts +3 -1
- package/scripts/summary.en.json +1 -1
- package/scripts/summary.zh.json +1 -1
- package/zh/apis/app/commands/_category_.json +1 -4
- package/zh/apis/app/hooks/_category_.json +1 -4
- package/zh/apis/app/hooks/src/pages.mdx +1 -1
- package/zh/apis/app/hooks/src/routes.mdx +1 -1
- package/zh/apis/app/runtime/_category_.json +1 -5
- package/zh/apis/app/runtime/core/create-app.mdx +1 -1
- package/zh/apis/app/runtime/core/use-module-apps.mdx +81 -40
- package/zh/apis/app/runtime/model/Provider.mdx +2 -2
- package/zh/apis/app/runtime/model/create-app.mdx +7 -7
- package/zh/apis/app/runtime/model/create-store.mdx +2 -2
- package/zh/apis/app/runtime/model/use-local-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-static-model.mdx +1 -1
- package/zh/apis/app/runtime/model/use-store.mdx +1 -1
- package/zh/apis/app/runtime/testing/renderApp.mdx +1 -1
- package/zh/components/micro-runtime-config.mdx +6 -6
- package/zh/components/release-note.mdx +1 -1
- package/zh/configure/app/builder-plugins.mdx +3 -3
- package/zh/configure/app/plugins.mdx +1 -1
- package/zh/configure/app/server/ssr-by-entries.mdx +1 -1
- package/zh/configure/app/tools/rspack.mdx +13 -0
- package/zh/configure/app/usage.mdx +1 -1
- package/zh/guides/advanced-features/_category_.json +2 -6
- package/zh/guides/advanced-features/compatibility.mdx +0 -1
- package/zh/guides/advanced-features/ssg.mdx +0 -1
- package/zh/guides/advanced-features/testing.mdx +0 -1
- package/zh/guides/advanced-features/web-server.mdx +0 -1
- package/zh/guides/basic-features/_category_.json +1 -5
- package/zh/guides/basic-features/alias.mdx +1 -1
- package/zh/guides/basic-features/data-fetch.mdx +35 -26
- package/zh/guides/basic-features/html.mdx +10 -9
- package/zh/guides/basic-features/mock.mdx +20 -0
- package/zh/guides/basic-features/routes.mdx +15 -10
- package/zh/guides/{basic-features → concept}/builder.mdx +2 -2
- package/zh/guides/concept/entries.mdx +11 -11
- package/zh/guides/css/_category_.json +5 -0
- package/zh/guides/{basic-features/css → css}/css-in-js.mdx +0 -0
- package/zh/guides/{basic-features/css → css}/css-modules.mdx +0 -0
- package/zh/guides/{basic-features/css → css}/less-sass.mdx +1 -1
- package/zh/guides/{basic-features/css → css}/postcss.mdx +5 -4
- package/zh/guides/{basic-features/css → css}/tailwindcss.mdx +0 -1
- package/zh/guides/get-started/introduction.mdx +31 -0
- package/zh/guides/get-started/quick-start.mdx +2 -3
- package/zh/guides/get-started/upgrade.mdx +2 -1
- package/zh/guides/topic-detail/_category_.json +2 -2
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +1 -1
- package/zh/guides/topic-detail/micro-frontend/c02-development.mdx +25 -0
- package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +15 -15
- package/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/zh/guides/troubleshooting/_category_.json +2 -2
- package/zh/index.md +1 -1
- package/zh/tutorials/first-app/_category_.json +1 -1
- package/zh/tutorials/first-app/c01-start.mdx +1 -2
- package/zh/tutorials/first-app/c03-css.mdx +1 -2
- package/zh/tutorials/first-app/c06-model.mdx +2 -2
- package/zh/tutorials/first-app/c07-container.mdx +1 -1
- package/zh/tutorials/first-app/c08-entries.mdx +2 -3
- package/zh/tutorials/foundations/introduction.mdx +14 -29
- package/en/apis/app/commands/index.mdx +0 -7
- package/en/apis/app/hooks/index.mdx +0 -7
- package/en/apis/app/runtime/index.mdx +0 -7
- package/en/guides/advanced-features/index.mdx +0 -7
- package/en/guides/basic-features/css/_category_.json +0 -4
- package/zh/apis/app/commands/index.mdx +0 -7
- package/zh/apis/app/hooks/index.mdx +0 -7
- package/zh/apis/app/runtime/index.mdx +0 -7
- package/zh/guides/advanced-features/index.mdx +0 -7
- package/zh/guides/basic-features/css/_category_.json +0 -4
- package/zh/guides/basic-features/index.mdx +0 -7
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
|
|
|
8
8
|
|
|
9
9
|
<ReduckTip />
|
|
10
10
|
|
|
11
|
-
用于把 Model 中的 State 作为局部状态使用,效果类似 React 的 `useState`。`useLocalModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.
|
|
11
|
+
用于把 Model 中的 State 作为局部状态使用,效果类似 React 的 `useState`。`useLocalModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.mdx)。
|
|
12
12
|
|
|
13
13
|
#### 示例
|
|
14
14
|
|
|
@@ -8,7 +8,7 @@ import ReduckTip from "@site-docs/components/reduck-tip"
|
|
|
8
8
|
|
|
9
9
|
<ReduckTip />
|
|
10
10
|
|
|
11
|
-
如果想在组件里以 React Hook 的形式消费某个 Model,并能随时获取到当前最新的状态,但又不希望 Model 状态更新的时候,引起组件的重新渲染,可以使用 `useStaticModel`。`useStaticModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.
|
|
11
|
+
如果想在组件里以 React Hook 的形式消费某个 Model,并能随时获取到当前最新的状态,但又不希望 Model 状态更新的时候,引起组件的重新渲染,可以使用 `useStaticModel`。`useStaticModel` API 形式上与 `useModel` 完全一致。具体使用请参考 [`useModel`](./use-model.mdx)。
|
|
12
12
|
|
|
13
13
|
为了保证总是能获取到最新状态,注意不要对返回的 `state` 解构。
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ function useStore(): ReduckStore;
|
|
|
18
18
|
|
|
19
19
|
### 返回值
|
|
20
20
|
|
|
21
|
-
- ReduckStore:Reduck Store,类型参考 [createStore](./create-store.
|
|
21
|
+
- ReduckStore:Reduck Store,类型参考 [createStore](./create-store.mdx) 返回值。
|
|
22
22
|
|
|
23
23
|
:::info 更多参考
|
|
24
24
|
[使用 Model](/guides/topic-detail/model/use-model#在组件外使用)
|
|
@@ -4,13 +4,13 @@ import { defineConfig } from '@modern-js/runtime';
|
|
|
4
4
|
defineConfig(App, {
|
|
5
5
|
masterApp: {
|
|
6
6
|
apps: [{
|
|
7
|
-
name: '
|
|
8
|
-
entry: 'http://localhost:
|
|
9
|
-
// activeWhen: '/
|
|
7
|
+
name: 'Table',
|
|
8
|
+
entry: 'http://localhost:8001',
|
|
9
|
+
// activeWhen: '/table'
|
|
10
10
|
}, {
|
|
11
|
-
name: '
|
|
12
|
-
entry: 'http://localhost:
|
|
13
|
-
// activeWhen: '/
|
|
11
|
+
name: 'Dashboard',
|
|
12
|
+
entry: 'http://localhost:8002'
|
|
13
|
+
// activeWhen: '/dashboard'
|
|
14
14
|
}]
|
|
15
15
|
},
|
|
16
16
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
根据官网 [Release Note](https://github.com/modern-js-dev/modern.js/releases
|
|
1
|
+
根据官网 [Release Note](https://github.com/modern-js-dev/modern.js/releases),开发者也可以手动将项目升级到想要的版本。
|
|
@@ -9,7 +9,7 @@ sidebar_position: 10
|
|
|
9
9
|
|
|
10
10
|
用于配置 Modern.js Builder 构建插件。
|
|
11
11
|
|
|
12
|
-
Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力](/guides/
|
|
12
|
+
Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力](/guides/concept/builder) 了解相关背景。
|
|
13
13
|
|
|
14
14
|
如果你想了解 Builder 插件的编写方式,可以参考 [Modern.js Builder - 插件系统](https://modernjs.dev/builder/plugins/introduction.html)。
|
|
15
15
|
|
|
@@ -17,13 +17,13 @@ Modern.js Builder 是 Modern.js 底层的构建引擎,请阅读 [构建能力]
|
|
|
17
17
|
|
|
18
18
|
该选项**用于配置 Modern.js Builder 构建插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
|
19
19
|
|
|
20
|
-
- 配置 Modern.js 框架插件,请使用 [plugins](
|
|
20
|
+
- 配置 Modern.js 框架插件,请使用 [plugins](/configure/app/plugins) 配置项。
|
|
21
21
|
- 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack) 或 [tools.webpackChain](/configure/app/tools/webpack-chain) 配置项。
|
|
22
22
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
|
23
23
|
|
|
24
24
|
## 何时使用
|
|
25
25
|
|
|
26
|
-
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](
|
|
26
|
+
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](/configure/app/plugins) 字段进行注册。因为框架插件提供的 API 更丰富、能力更强,而 Builder 插件提供的 API 只能用于构建场景。
|
|
27
27
|
|
|
28
28
|
当你需要引用一些现有的 Builder 插件(并且在 Modern.js 中没有相关能力),或是在不同的框架之间复用 Builder 插件时,你可以使用 `builderPlugins` 字段进行注册。
|
|
29
29
|
|
|
@@ -15,7 +15,7 @@ sidebar_position: 9
|
|
|
15
15
|
|
|
16
16
|
该选项**用于配置框架插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
|
17
17
|
|
|
18
|
-
- 配置 Modern.js Builder 插件,请使用 [builderPlugins](
|
|
18
|
+
- 配置 Modern.js Builder 插件,请使用 [builderPlugins](/configure/app/builder-plugins) 配置项。
|
|
19
19
|
- 配置 webpack 插件,请使用 [tools.webpack](/configure/app/tools/webpack) 或 [tools.webpackChain](/configure/app/tools/webpack-chain) 配置项。
|
|
20
20
|
- 配置 Babel 插件,请使用 [tools.babel](/configure/app/tools/babel) 配置项。
|
|
21
21
|
|
|
@@ -7,7 +7,7 @@ sidebar_label: ssrByEntries
|
|
|
7
7
|
- **类型:** `Object`
|
|
8
8
|
- **默认值:** `undefined`
|
|
9
9
|
|
|
10
|
-
按入口设置 ssr 选项,选项内的属性同 [ssr](./ssr.
|
|
10
|
+
按入口设置 ssr 选项,选项内的属性同 [ssr](./ssr.mdx),指定值会和 ssr 属性内容做替换合并操作,例如:
|
|
11
11
|
|
|
12
12
|
:::info
|
|
13
13
|
「 入口名 」默认为目录名,少数情况下通过 `source.entries` 自定义入口时,入口名为 `source.entries` 对象的 `key`。
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_label: rspack
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# tools.rspack
|
|
6
|
+
|
|
7
|
+
:::tip
|
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.rspack](https://modernjs.dev/builder/api/config-tools.html#toolsrspack)。
|
|
9
|
+
:::
|
|
10
|
+
|
|
11
|
+
import Main from '@modern-js/builder-doc/docs/zh/config/tools/rspack.md'
|
|
12
|
+
|
|
13
|
+
<Main />
|
|
@@ -12,7 +12,7 @@ Modern.js 中有两种配置,一个是编译时配置,一个是服务端运
|
|
|
12
12
|
- `package.json` 文件
|
|
13
13
|
|
|
14
14
|
:::info
|
|
15
|
-
不支持同时在 package.json 中和 modern.config.ts 中配置同一个配置项,推荐优先在 modern.config.ts 中进行配置。如果 Modern.js 检测到重复配置导致的冲突,将会抛出警告。
|
|
15
|
+
Modern.js 不支持同时在 package.json 中和 modern.config.ts 中配置同一个配置项,推荐优先在 modern.config.ts 中进行配置。如果 Modern.js 检测到重复配置导致的冲突,将会抛出警告。
|
|
16
16
|
:::
|
|
17
17
|
|
|
18
18
|
服务端运行时配置可以在根路径下的 `modern.server-runtime.config.(ts|js|mjs)` 中自定义配置选项。
|
|
@@ -55,7 +55,6 @@ Modern.js 中还提供了基于浏览器 [UA](https://developer.mozilla.org/zh-C
|
|
|
55
55
|
```ts title="modern.config.ts"
|
|
56
56
|
import polyfillPlugin from '@modern-js/plugin-polyfill';
|
|
57
57
|
|
|
58
|
-
// https://modernjs.dev/docs/apis/app/config
|
|
59
58
|
export default defineConfig({
|
|
60
59
|
plugins: [..., polyfillPlugin()],
|
|
61
60
|
});
|
|
@@ -20,7 +20,6 @@ Modern.js 默认继承了 [Jest](https://jestjs.io/) 的测试能力。
|
|
|
20
20
|
```ts title="modern.config.ts"
|
|
21
21
|
import testPlugin from '@modern-js/plugin-testing';
|
|
22
22
|
|
|
23
|
-
// https://modernjs.dev/docs/apis/app/config
|
|
24
23
|
export default defineConfig({
|
|
25
24
|
...,
|
|
26
25
|
plugins: [..., testPlugin()],
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
title: 数据获取
|
|
3
3
|
sidebar_position: 3
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# 数据获取
|
|
6
7
|
|
|
7
8
|
Modern.js 中提供了开箱即用的数据获取能力,开发者可以通过这些 API,在 CSR 和 SSR 环境同构的进行开发。
|
|
@@ -220,38 +221,46 @@ export default function UserLayout() {
|
|
|
220
221
|
|
|
221
222
|
:::
|
|
222
223
|
|
|
224
|
+
创建 `user/layout.loader.ts`,并添加以下代码:
|
|
225
|
+
|
|
226
|
+
```ts title="routes/user/layout.loader.ts"
|
|
227
|
+
import { defer } from "@edenx/runtime/router"
|
|
228
|
+
|
|
229
|
+
const loader = () =>
|
|
230
|
+
defer({
|
|
231
|
+
userInfo: new Promise((resolve) => {
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
resolve({
|
|
234
|
+
age: 1,
|
|
235
|
+
name: 'user layout'
|
|
236
|
+
})
|
|
237
|
+
}, 1000)
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
export default loader;
|
|
242
|
+
```
|
|
243
|
+
|
|
223
244
|
在 `user/layout.tsx` 中添加以下代码:
|
|
224
245
|
|
|
225
246
|
```tsx title="routes/user/layout.tsx"
|
|
226
|
-
import {
|
|
227
|
-
Await,
|
|
228
|
-
defer,
|
|
229
|
-
useLoaderData,
|
|
230
|
-
Outlet
|
|
231
|
-
} from '@modern-js/runtime/router';
|
|
232
|
-
|
|
233
|
-
export const loader = () => {
|
|
234
|
-
return defer({
|
|
235
|
-
// fetchUserInfo 是一个异步函数,返回用户信息
|
|
236
|
-
userInfo: fetchUserInfo(),
|
|
237
|
-
})
|
|
238
|
-
}
|
|
247
|
+
import { Await, defer, useLoaderData, Outlet } from '@modern-js/runtime/router';
|
|
239
248
|
|
|
240
249
|
export default function UserLayout() {
|
|
241
|
-
const { userInfo } = useLoaderData() as {userInfo: Promise<UserInfo>};
|
|
250
|
+
const { userInfo } = useLoaderData() as { userInfo: Promise<UserInfo> };
|
|
242
251
|
return (
|
|
243
252
|
<div>
|
|
244
|
-
<React.Suspense
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
<React.Suspense fallback={<p>Loading...</p>}>
|
|
254
|
+
<Await
|
|
255
|
+
resolve={userInfo}
|
|
256
|
+
children={userInfo => (
|
|
257
|
+
<div>
|
|
258
|
+
<span>{userInfo.name}</span>
|
|
259
|
+
<span>{userInfo.age}</span>
|
|
260
|
+
<Outlet />
|
|
261
|
+
</div>
|
|
262
|
+
)}
|
|
263
|
+
></Await>
|
|
255
264
|
</React.Suspense>
|
|
256
265
|
</div>
|
|
257
266
|
);
|
|
@@ -265,7 +274,7 @@ defer 的具体用法请查看 [defer](https://reactrouter.com/en/main/guides/de
|
|
|
265
274
|
|
|
266
275
|
:::
|
|
267
276
|
|
|
268
|
-
{/* TODO 缓存相关
|
|
277
|
+
{/* TODO 缓存相关 */}
|
|
269
278
|
|
|
270
279
|
### 错误用法
|
|
271
280
|
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
title: HTML 模板
|
|
3
3
|
sidebar_position: 9
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# HTML 模板
|
|
6
7
|
|
|
7
|
-
Modern.js 提供了 **JSX
|
|
8
|
+
Modern.js 提供了 **JSX 语法**和 **HTML(EJS) 语法**两种方式用于自定义 HTML 模板。
|
|
8
9
|
|
|
9
10
|
## JSX 语法
|
|
10
11
|
|
|
@@ -14,14 +15,14 @@ Modern.js 约定,在 `src/` 目录下,或在入口目录下,可以创建 `
|
|
|
14
15
|
|
|
15
16
|
```bash
|
|
16
17
|
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
│
|
|
21
|
-
│
|
|
22
|
-
|
|
23
|
-
│
|
|
24
|
-
|
|
18
|
+
└── src
|
|
19
|
+
├── Document.tsx
|
|
20
|
+
├── entry-a
|
|
21
|
+
│ ├── Document.tsx
|
|
22
|
+
│ └── routes
|
|
23
|
+
├── entry-b
|
|
24
|
+
│ └── routes
|
|
25
|
+
└── modern-app-env.d.ts
|
|
25
26
|
```
|
|
26
27
|
|
|
27
28
|
`entry-a` 会优先使用当前入口下的 `Docoument.[jt]sx` 文件。如果当前入口没有 `Document.[jt]sx` 文件,例如 `entry-b`,则会查找根目录下的 `Document.[jt]sx` 文件。
|
|
@@ -77,3 +77,23 @@ module.exports = {
|
|
|
77
77
|
},
|
|
78
78
|
};
|
|
79
79
|
```
|
|
80
|
+
|
|
81
|
+
## 按需使用 Mock 服务
|
|
82
|
+
|
|
83
|
+
`config/mock/index.ts` 下还可以到处 `config` 对象,更精细的控制 Mock 服务。
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
type MockConfig = {
|
|
87
|
+
enable: ((req: IncomingMessage, res: ServerResponse) => boolean) | boolean;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const config = {
|
|
91
|
+
enable: false
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
目前仅支持 `enable` 配置,开发者可以通过该配置控制是否执行 Mock。
|
|
96
|
+
|
|
97
|
+
:::note
|
|
98
|
+
修改 `config` 后无需重启服务,即刻生效。
|
|
99
|
+
:::
|
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
|
4
4
|
---
|
|
5
5
|
# 路由
|
|
6
6
|
|
|
7
|
-
Modern.js 的路由基于 [React Router 6](https://reactrouter.com/en/main),并提供了多种类型的路由模式。根据不同[入口](/
|
|
7
|
+
Modern.js 的路由基于 [React Router 6](https://reactrouter.com/en/main),并提供了多种类型的路由模式。根据不同 [入口](/guides/concept/entries) 类型,将路由分为三种模式,分别是**约定式路由**,**自控式路由**和**其他路由方案**。
|
|
8
8
|
|
|
9
9
|
:::note
|
|
10
10
|
本小节提到的路由,都是客户端路由,即 SPA 路由。
|
|
@@ -164,7 +164,7 @@ export default () => {
|
|
|
164
164
|
|
|
165
165
|
`routes/[id]/page.tsx` 文件会转为 `/:id` 路由。除了可以确切匹配的 `/blog` 路由,其他所有 `/xxx` 都会匹配到该路由。
|
|
166
166
|
|
|
167
|
-
在组件中,可以通过 [useParams](/apis/app/runtime/router
|
|
167
|
+
在组件中,可以通过 [useParams](/apis/app/runtime/router/router#useparams) 获取对应命名的参数。
|
|
168
168
|
|
|
169
169
|
在 loader 中,params 会作为 [loader](/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params.xxx` 可以获取。
|
|
170
170
|
|
|
@@ -185,7 +185,7 @@ export default () => {
|
|
|
185
185
|
└── page.tsx
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
当访问任何匹配不到的路径时,都会渲染 `routes/$.tsx` 组件,同样,`$.tsx` 中可以使用 [useParams](/apis/app/runtime/router
|
|
188
|
+
当访问任何匹配不到的路径时,都会渲染 `routes/$.tsx` 组件,同样,`$.tsx` 中可以使用 [useParams](/apis/app/runtime/router/router#useparams) 捕获 url 的剩余部分。
|
|
189
189
|
```ts title="$.tsx"
|
|
190
190
|
import { useParams } from '@modern-js/runtime/router';
|
|
191
191
|
// 当 path 是 `/aaa/bbb` 时
|
|
@@ -302,7 +302,7 @@ Modern.js 建议必须有根 layout 和根 loading。
|
|
|
302
302
|
|
|
303
303
|
{/* Todo API 路由 */}
|
|
304
304
|
|
|
305
|
-
在 `<ErrorBoundary>` 组件内,可以使用 [useRouteError](/apis/app/runtime/router
|
|
305
|
+
在 `<ErrorBoundary>` 组件内,可以使用 [useRouteError](/apis/app/runtime/router/router#useparams) 获取的错误的具体信息:
|
|
306
306
|
|
|
307
307
|
```tsx
|
|
308
308
|
import { useRouteError } from '@modern-js/runtime/router';
|
|
@@ -329,8 +329,15 @@ import type { AppConfig } from '@modern-js/runtime';
|
|
|
329
329
|
export const config = (): AppConfig => {
|
|
330
330
|
return {
|
|
331
331
|
router: {
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
createRoutes() {
|
|
333
|
+
return [
|
|
334
|
+
{
|
|
335
|
+
path: 'edenx',
|
|
336
|
+
element: <div>edenx</div>,
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
},
|
|
340
|
+
},
|
|
334
341
|
}
|
|
335
342
|
};
|
|
336
343
|
```
|
|
@@ -380,12 +387,10 @@ export default () => {
|
|
|
380
387
|
配合 SSR 功能时,浏览器端可以获取到 SSR 时 `init` 返回的数据,开发者可以自行判断是否要在浏览器端重新获取数据来覆盖 SSR 数据,例如:
|
|
381
388
|
|
|
382
389
|
```tsx title="src/routes/layout.tsx"
|
|
383
|
-
import {
|
|
384
|
-
RuntimeContext,
|
|
385
|
-
} from '@modern-js/runtime';
|
|
390
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
386
391
|
|
|
387
392
|
export const init = (context: RuntimeContext) => {
|
|
388
|
-
if (process.env.
|
|
393
|
+
if (process.env.MODERN_TARGET === 'node') {
|
|
389
394
|
return {
|
|
390
395
|
message: 'Hello World By Server',
|
|
391
396
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
sidebar_position: 2
|
|
2
|
+
sidebar_position: 1
|
|
4
3
|
---
|
|
4
|
+
|
|
5
5
|
# 入口
|
|
6
6
|
|
|
7
7
|
入口是 Modern.js 默认的文件约定,项目的每一个入口是一张独立的页面,对应一条**服务端路由**。
|
|
@@ -15,11 +15,11 @@ Modern.js 初始化的项目是单入口的,项目结构如下:
|
|
|
15
15
|
```
|
|
16
16
|
.
|
|
17
17
|
├── src
|
|
18
|
-
│
|
|
19
|
-
│
|
|
20
|
-
│
|
|
21
|
-
│
|
|
22
|
-
│
|
|
18
|
+
│ ├── modern-app-env.d.ts
|
|
19
|
+
│ └── routes
|
|
20
|
+
│ ├── index.css
|
|
21
|
+
│ ├── layout.tsx
|
|
22
|
+
│ └── page.tsx
|
|
23
23
|
├── package.json
|
|
24
24
|
├── modern.config.ts
|
|
25
25
|
├── pnpm-lock.yaml
|
|
@@ -41,10 +41,10 @@ Modern.js 可以很方便的将单入口切换成多入口。可以在项目下
|
|
|
41
41
|
.
|
|
42
42
|
├── modern-app-env.d.ts
|
|
43
43
|
├── myapp
|
|
44
|
-
│
|
|
45
|
-
│
|
|
46
|
-
│
|
|
47
|
-
│
|
|
44
|
+
│ └── routes
|
|
45
|
+
│ ├── index.css
|
|
46
|
+
│ ├── layout.tsx
|
|
47
|
+
│ └── page.tsx
|
|
48
48
|
└── new-entry
|
|
49
49
|
└── routes
|
|
50
50
|
├── index.css
|
|
File without changes
|
|
File without changes
|
|
@@ -12,6 +12,6 @@ sidebar_position: 4
|
|
|
12
12
|
- 如果需要自定义 [sass-loader](https://github.com/webpack-contrib/sass-loader) 的配置,请参考 [tools.less](/configure/app/tools/sass) 配置项。
|
|
13
13
|
|
|
14
14
|
:::tip 提示
|
|
15
|
-
经过 Less 和 Sass 预编译后的 CSS 文件,仍然会经过 Modern.js 内置的 [PostCSS](https://postcss.org/) 的转换,具备良好的浏览器兼容性。相关内容请参考【[PostCSS](/guides/
|
|
15
|
+
经过 Less 和 Sass 预编译后的 CSS 文件,仍然会经过 Modern.js 内置的 [PostCSS](https://postcss.org/) 的转换,具备良好的浏览器兼容性。相关内容请参考【[PostCSS](/guides/css/postcss)】。
|
|
16
16
|
|
|
17
17
|
:::
|
|
@@ -10,10 +10,11 @@ sidebar_position: 3
|
|
|
10
10
|
|
|
11
11
|
1. [Autoprefixer](https://github.com/postcss/autoprefixer) 根据需要支持的浏览器范围,会自动为 CSS 规则添加需要的浏览器厂商前缀。Modern.js 默认支持的浏览器范围为:`['> 0.01%', 'not dead', 'not op_mini all']`。
|
|
12
12
|
|
|
13
|
-
:::info
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
:::info 注意
|
|
14
|
+
|
|
15
|
+
- 【支持的浏览器范围为:`> 0.01%`】是指浏览器市场份额大于 0.01%。
|
|
16
|
+
- `not dead` 是指不包含官方不再支持的浏览器和过去 24 个月没有更新的浏览器。
|
|
17
|
+
- `not op_mini all` 是指不包含 Opera Mini。
|
|
17
18
|
|
|
18
19
|
:::
|
|
19
20
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 介绍
|
|
3
|
+
sidebar_position: 1
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Modern.js 介绍
|
|
7
|
+
|
|
8
|
+
**Modern.js** 是基于 React 的渐进式现代 Web 开发框架。
|
|
9
|
+
|
|
10
|
+
框架内置多种开箱即用的开发工具,拥有极致的构建性能,支持零配置的渲染范式切换,一体化的 API 调用。并从三种工程方案出发(应用工程方案、模块工程方案,Monorepo 工程方案),支持全链路的前端研发。
|
|
11
|
+
|
|
12
|
+
Modern.js 是字节跳动的底层前端研发框架,已经直接或间接的服务上千个应用,包括中后台、PC Web、H5 等多种应用场景。框架覆盖完整的生命周期,拥有完善的插件体系,提供高度定制能力。支持通过生成器插件自定义业务线专属的工程方案,定制各种功能扩展和业务需求,帮助开发者更快速的搭建应用。
|
|
13
|
+
|
|
14
|
+
## 为什么使用 Modern.js
|
|
15
|
+
|
|
16
|
+
Modern.js 能为开发者提供极致的**开发体验(Development Experience)**,让应用拥有更好的**用户体验(User Experience)**。
|
|
17
|
+
|
|
18
|
+
在开发 React 应用过程中,开发者通常需要去为某些功能去设计实现方案,或是使用其他的库、框架来解决这些问题。Modern.js 支持 React 应用所需要的所有配置和工具,并内置**额外的功能和优化**。开发者可以使用 React 构建应用的 UI,然后逐步采用 Modern.js 的功能来解决常见的应用需求,如路由、数据获取、状态管理等。
|
|
19
|
+
|
|
20
|
+
它主要包含以下特点:
|
|
21
|
+
|
|
22
|
+
- 🪜 **渐进式**:使用最精简的模板创建项目,通过生成器逐步开启插件功能,定制解决方案。
|
|
23
|
+
- 🏠 **一体化**:开发与生产环境 Web Server 唯一,CSR 和 SSR 同构开发,函数即接口的 API 服务调用。
|
|
24
|
+
- 📦 **开箱即用**:默认 TS 支持,内置构建、ESLint、调试工具,全功能可测试。
|
|
25
|
+
- 🌏 **周边生态**:自研状态管理、微前端、模块打包、Monorepo 方案等周边需求。
|
|
26
|
+
- 🕸 **多种路由模式**:包含自控路由、基于文件约定的路由(嵌套路由)等。
|
|
27
|
+
- 🚀 **独立构建核心**:支持多种打包工具,深度优化构建产物。
|
|
28
|
+
|
|
29
|
+
## 下一步
|
|
30
|
+
|
|
31
|
+
如果你希望了解如何使用 Modern.js,可以尝试 [创建第一个应用](/tutorials/first-app/c01-start),或是阅读 [快速上手](/guides/get-started/quick-start)。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: 快速上手
|
|
3
|
-
sidebar_position:
|
|
3
|
+
sidebar_position: 2
|
|
4
4
|
---
|
|
5
5
|
# 快速上手
|
|
6
6
|
|
|
@@ -45,10 +45,9 @@ import DebugApp from "@site-docs/components/debug-app"
|
|
|
45
45
|
|
|
46
46
|
可以通过配置文件来开启功能,或覆盖 Modern.js 的默认行为。例如添加如下配置,开启 SSR:
|
|
47
47
|
|
|
48
|
-
```ts
|
|
48
|
+
```ts title="modern.config.ts"
|
|
49
49
|
import appTools, { defineConfig } from '@modern-js/app-tools';
|
|
50
50
|
|
|
51
|
-
// https://modernjs.dev/docs/apis/app/config
|
|
52
51
|
export default defineConfig({
|
|
53
52
|
runtime: {
|
|
54
53
|
router: true,
|
|
@@ -251,6 +251,31 @@ export default (props: {basename: string}) => {
|
|
|
251
251
|
|
|
252
252
|
在完成了微前端整体开发流程的体验后,你可以进一步了解如何 [开发主应用](/guides/topic-detail/micro-frontend/c03-main-app)
|
|
253
253
|
|
|
254
|
+
## Modern.js 微前端和直接使用 Garfish 的区别
|
|
255
|
+
|
|
256
|
+
使用纯 `Garfish` API 开发微前端应用时
|
|
257
|
+
- 主应用:
|
|
258
|
+
- 安装 Garfish 依赖并使用 `Garfish.run` 注册子应用 [参考](https://www.garfishjs.org/api/run)
|
|
259
|
+
- 提供一个常驻的 `DOM` 节点供子应用挂载 [参考](https://www.garfishjs.org/api/registerApp#domgetter)
|
|
260
|
+
- 子应用:
|
|
261
|
+
- 导出 `provider` [参考](https://www.garfishjs.org/guide/start#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)
|
|
262
|
+
- 设置应用的 `basename` [参考](https://www.garfishjs.org/guide/start#3-%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E8%B7%AF%E7%94%B1-basename)
|
|
263
|
+
|
|
264
|
+
区别于直接使用 `Garfish` 运行时 API 开发微前端项目,`Modern.js` 的微前端方案更加开箱即用。
|
|
265
|
+
使用 `pnpm new` 启用微前端模式后会自动在 `Modern.js` 应用中集成 `Garfish` 插件,在 `Garfish`
|
|
266
|
+
插件的加持下,你只需要
|
|
267
|
+
- 主应用:
|
|
268
|
+
- 配置 `runtime.masterApp.apps` 参数注册子应用
|
|
269
|
+
- 使用 `useModuleApps` API 获取子应用实例并在组件中完成渲染
|
|
270
|
+
- 子应用:
|
|
271
|
+
- 配置 `deploy.microFrontend`
|
|
272
|
+
|
|
273
|
+
所以插件中为你做了如下事情
|
|
274
|
+
- 帮助你通过 `Garfish` 运行时 API 自动注册子应用(主应用)
|
|
275
|
+
- `useModulesApps` 函数的返回值提供了一个常驻的 `DOM` 节点供子应用挂载(主应用)
|
|
276
|
+
- 帮助你正确导出了 `provider`(子应用)
|
|
277
|
+
- 帮助你正确设置了 `basename` 给 `Modern.js` 运行时提供 `Router` 实例,如果是`自控式路由`或`手动引入的 react-router-dom` 那么需要从 `App.tsx` 的 `props` 中获取 `basename` 手动传递给引入的 `Router 实例`(子应用)
|
|
278
|
+
|
|
254
279
|
## 常见问题
|
|
255
280
|
|
|
256
281
|
自查手册: https://www.garfishjs.org/issues/
|