@modern-js/main-doc 2.0.0-beta.2 → 2.0.0-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +0 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +17 -3
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +0 -22
- package/en/docusaurus-plugin-content-docs/current/components/reduck-migration.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/asset-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/hmr.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/https.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/port.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/progress-bar.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/dev/start-url.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/experiments/lazy-compilation.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/app-icon.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/crossorigin.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/disable-html-folder.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/mount-id.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/template.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/title-by-entries.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/html/title.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/asset-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/assets-retry.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/charset.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/clean-dist-path.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/convert-to-rem.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/copy.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/css-module-local-ident-name.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/data-uri-limit.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-extract.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-module-extension.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-filename-hash.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-inline-runtime-chunk.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-minimize.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-source-map.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-ts-checker.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/dist-path.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-fallback.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-manifest.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-scripts.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-styles.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-latest-decorators.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/externals.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/filename.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/legal-comments.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/override-browserslist.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/polyfill.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/output/svg-default-export.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/build-cache.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/bundle-analyze.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/chunk-split.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/print-file-size.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/profile.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-console.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-moment-locale.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/security/sri.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/alias.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/compile-js-data-uri.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/define.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/exclude.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/global-vars.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/include.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/module-scopes.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/pre-entry.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-extension-prefix.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-main-fields.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/autoprefixer.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/babel.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-extract.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/dev-server.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/html-plugin.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/inspector.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/less.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/minify-css.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/postcss.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/pug.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/sass.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/style-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/styled-components.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/swc.md +42 -0
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/terser.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-checker.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-loader.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack-chain.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/guides/basic-features/builder.md +46 -0
- package/en/docusaurus-plugin-content-docs/current.json +18 -18
- package/package.json +3 -3
- package/scripts/config.ts +2 -2
- package/zh/apis/app/commands/new.md +0 -2
- package/zh/apis/app/runtime/app/_category_.json +1 -1
- package/zh/apis/app/runtime/bff/_category_.json +1 -1
- package/zh/apis/app/runtime/core/_category_.json +1 -1
- package/zh/apis/app/runtime/core/bootstrap.md +17 -3
- package/zh/apis/app/runtime/model/_category_.json +1 -1
- package/zh/apis/app/runtime/model/create-app.md +1 -1
- package/zh/apis/app/runtime/model/use-store.md +1 -23
- package/zh/apis/app/runtime/router/_category_.json +1 -1
- package/zh/apis/app/runtime/ssr/_category_.json +1 -1
- package/zh/apis/app/runtime/testing/_category_.json +1 -1
- package/zh/apis/app/runtime/utility/_category_.json +1 -1
- package/zh/apis/app/runtime/web-server/_category_.json +1 -1
- package/zh/components/reduck-migration.md +1 -0
- package/zh/configure/app/dev/asset-prefix.md +1 -1
- package/zh/configure/app/dev/hmr.md +1 -1
- package/zh/configure/app/dev/https.md +1 -1
- package/zh/configure/app/dev/port.md +1 -1
- package/zh/configure/app/dev/progress-bar.md +1 -1
- package/zh/configure/app/dev/start-url.md +1 -1
- package/zh/configure/app/experiments/_category_.json +4 -0
- package/zh/configure/app/experiments/lazy-compilation.md +1 -1
- package/zh/configure/app/html/_category_.json +4 -0
- package/zh/configure/app/html/app-icon.md +1 -1
- package/zh/configure/app/html/crossorigin.md +1 -1
- package/zh/configure/app/html/disable-html-folder.md +1 -1
- package/zh/configure/app/html/favicon-by-entries.md +1 -1
- package/zh/configure/app/html/favicon.md +1 -1
- package/zh/configure/app/html/inject-by-entries.md +1 -1
- package/zh/configure/app/html/inject.md +1 -1
- package/zh/configure/app/html/meta-by-entries.md +1 -1
- package/zh/configure/app/html/meta.md +1 -1
- package/zh/configure/app/html/mount-id.md +1 -1
- package/zh/configure/app/html/template-by-entries.md +1 -1
- package/zh/configure/app/html/template-parameters-by-entries.md +1 -1
- package/zh/configure/app/html/template-parameters.md +1 -1
- package/zh/configure/app/html/template.md +1 -1
- package/zh/configure/app/html/title-by-entries.md +1 -1
- package/zh/configure/app/html/title.md +1 -1
- package/zh/configure/app/output/asset-prefix.md +1 -1
- package/zh/configure/app/output/assets-retry.md +1 -1
- package/zh/configure/app/output/charset.md +1 -1
- package/zh/configure/app/output/clean-dist-path.md +1 -1
- package/zh/configure/app/output/convert-to-rem.md +1 -1
- package/zh/configure/app/output/copy.md +1 -1
- package/zh/configure/app/output/css-module-local-ident-name.md +1 -1
- package/zh/configure/app/output/data-uri-limit.md +1 -1
- package/zh/configure/app/output/disable-css-extract.md +1 -1
- package/zh/configure/app/output/disable-css-module-extension.md +1 -1
- package/zh/configure/app/output/disable-filename-hash.md +1 -1
- package/zh/configure/app/output/disable-inline-runtime-chunk.md +1 -1
- package/zh/configure/app/output/disable-minimize.md +1 -1
- package/zh/configure/app/output/disable-source-map.md +1 -1
- package/zh/configure/app/output/disable-ts-checker.md +1 -1
- package/zh/configure/app/output/dist-path.md +1 -1
- package/zh/configure/app/output/enable-asset-fallback.md +1 -1
- package/zh/configure/app/output/enable-asset-manifest.md +1 -1
- package/zh/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
- package/zh/configure/app/output/enable-inline-scripts.md +1 -1
- package/zh/configure/app/output/enable-inline-styles.md +1 -1
- package/zh/configure/app/output/enable-latest-decorators.md +1 -1
- package/zh/configure/app/output/externals.md +1 -1
- package/zh/configure/app/output/filename.md +1 -1
- package/zh/configure/app/output/legal-comments.md +1 -1
- package/zh/configure/app/output/override-browserslist.md +1 -1
- package/zh/configure/app/output/polyfill.md +1 -1
- package/zh/configure/app/output/ssg.md +118 -114
- package/zh/configure/app/output/svg-default-export.md +1 -1
- package/zh/configure/app/performance/_category_.json +4 -0
- package/zh/configure/app/performance/build-cache.md +1 -1
- package/zh/configure/app/performance/bundle-analyze.md +1 -1
- package/zh/configure/app/performance/chunk-split.md +1 -1
- package/zh/configure/app/performance/print-file-size.md +1 -1
- package/zh/configure/app/performance/profile.md +1 -1
- package/zh/configure/app/performance/remove-console.md +1 -1
- package/zh/configure/app/performance/remove-moment-locale.md +1 -1
- package/zh/configure/app/plugins.md +1 -1
- package/zh/configure/app/runtime/state.md +13 -0
- package/zh/configure/app/security/_category_.json +4 -0
- package/zh/configure/app/security/sri.md +1 -1
- package/zh/configure/app/server/ssr.md +0 -2
- package/zh/configure/app/source/alias.md +1 -1
- package/zh/configure/app/source/compile-js-data-uri.md +1 -1
- package/zh/configure/app/source/define.md +1 -1
- package/zh/configure/app/source/exclude.md +1 -1
- package/zh/configure/app/source/global-vars.md +1 -1
- package/zh/configure/app/source/include.md +1 -1
- package/zh/configure/app/source/module-scopes.md +1 -1
- package/zh/configure/app/source/pre-entry.md +1 -1
- package/zh/configure/app/source/resolve-extension-prefix.md +1 -1
- package/zh/configure/app/source/resolve-main-fields.md +1 -1
- package/zh/configure/app/tools/autoprefixer.md +1 -1
- package/zh/configure/app/tools/babel.md +1 -1
- package/zh/configure/app/tools/css-extract.md +1 -1
- package/zh/configure/app/tools/css-loader.md +1 -1
- package/zh/configure/app/tools/dev-server.md +1 -1
- package/zh/configure/app/tools/html-plugin.md +1 -1
- package/zh/configure/app/tools/inspector.md +1 -1
- package/zh/configure/app/tools/less.md +1 -1
- package/zh/configure/app/tools/minify-css.md +1 -1
- package/zh/configure/app/tools/postcss.md +1 -1
- package/zh/configure/app/tools/pug.md +1 -1
- package/zh/configure/app/tools/sass.md +1 -1
- package/zh/configure/app/tools/style-loader.md +1 -1
- package/zh/configure/app/tools/styled-components.md +1 -1
- package/zh/configure/app/tools/swc.md +42 -0
- package/zh/configure/app/tools/terser.md +1 -1
- package/zh/configure/app/tools/ts-checker.md +1 -1
- package/zh/configure/app/tools/ts-loader.md +1 -1
- package/zh/configure/app/tools/webpack-chain.md +1 -1
- package/zh/configure/app/tools/webpack.md +1 -1
- package/zh/guides/advanced-features/custom-app.md +8 -2
- package/zh/guides/advanced-features/ssg.md +74 -63
- package/zh/guides/advanced-features/ssr.md +74 -11
- package/zh/guides/basic-features/builder.md +46 -0
- package/zh/guides/basic-features/css/_category_.json +1 -1
- package/zh/guides/basic-features/css/less-sass.md +1 -14
- package/zh/guides/basic-features/data-fetch.md +1 -1
- package/zh/guides/basic-features/env-vars.md +34 -0
- package/zh/guides/basic-features/routes.md +32 -35
- package/zh/guides/concept/entries.md +4 -4
- package/zh/guides/topic-detail/framework-plugin/extend.md +3 -4
- package/zh/{apis/app/runtime/plugin/hook-api.md → guides/topic-detail/framework-plugin/hook-list.md} +42 -135
- package/zh/{apis/app/runtime/plugin → guides/topic-detail/framework-plugin}/hook.md +2 -3
- package/zh/guides/topic-detail/framework-plugin/implement.md +21 -10
- package/zh/guides/topic-detail/framework-plugin/introduction.md +49 -0
- package/{en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin → zh/guides/topic-detail/framework-plugin}/plugin-api.md +3 -4
- package/zh/guides/topic-detail/framework-plugin/relationship.md +2 -3
- package/zh/guides/topic-detail/model/quick-start.md +4 -0
- package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +2 -2
- package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +5 -2
- package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +4 -6
- package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +2 -4
- package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +1 -1
- package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +44 -50
- package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +1 -1
- package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +4 -4
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +8 -21
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +37 -13
- package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +3 -13
- package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +1 -21
- package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +9 -9
- package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +9 -14
- package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +7 -7
- package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +1 -1
- package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +2 -2
- package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +8 -17
- package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +23 -18
- package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +30 -30
- package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +4 -9
- package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +66 -63
- package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +35 -33
- package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +28 -102
- package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +4 -6
- package/zh/tutorials/first-app/c10-model/10.2-add-model.md +3 -3
- package/zh/tutorials/first-app/c10-model/10.3-use-model.md +21 -20
- package/zh/tutorials/first-app/c10-model/10.4-testing.md +2 -2
- package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +34 -68
- package/zh/tutorials/first-app/c11-container/11.2-add-container.md +40 -37
- package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +6 -4
- package/zh/tutorials/first-app/c11-container/11.4-testing.md +2 -2
- package/zh/tutorials/foundations/introduction.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -25
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/_category_.json +0 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/abstract.md +0 -26
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook-api.md +0 -896
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook.md +0 -170
- package/zh/apis/app/runtime/default-alias.md +0 -23
- package/zh/apis/app/runtime/plugin/_category_.json +0 -4
- package/zh/apis/app/runtime/plugin/abstract.md +0 -26
- package/zh/apis/app/runtime/plugin/plugin-api.md +0 -117
- package/zh/guides/basic-features/image.md +0 -43
- package/zh/guides/topic-detail/compile-speed.md +0 -182
- package/zh/guides/topic-detail/framework-plugin/abstract.md +0 -27
- package/zh/guides/troubleshooting/compile.md +0 -379
- package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +0 -310
@@ -1,11 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title:
|
2
|
+
title: 服务端渲染(SSR)
|
3
3
|
sidebar_position: 3
|
4
4
|
---
|
5
5
|
|
6
|
-
在 Modern.js
|
6
|
+
在 Modern.js 中,SSR 也是开箱即用的。开发者无需为 SSR 编写复杂的服务端逻辑,也无需关心 SSR 的运维,或是创建单独的服务。Modern.js 拥有完备的 SSR 降级策略,保证页面能够安全运行。
|
7
7
|
|
8
|
-
|
8
|
+
启用 SSR 非常简单,只需要设置 [`server.ssr`](/docs/configure/app/server/ssr) 为 `true` 即可:
|
9
9
|
|
10
10
|
```json title="package.json"
|
11
11
|
{
|
@@ -15,9 +15,9 @@ Modern.js 启用 SSR 非常简单,只需要设置 [`server.ssr`](/docs/configu
|
|
15
15
|
}
|
16
16
|
```
|
17
17
|
|
18
|
-
## SSR
|
18
|
+
## SSR 时的数据获取
|
19
19
|
|
20
|
-
Modern.js 中提供了 `useLoader` Hooks API
|
20
|
+
Modern.js 中提供了 [`useLoader`](/docs/apis/app/runtime/core/use-loader) Hooks API,用于在 SSR 环境下同构的获取数据:
|
21
21
|
|
22
22
|
```ts
|
23
23
|
const { data, loading, error } = useLoader(() => {
|
@@ -30,16 +30,14 @@ Modern.js 打破传统的 SSR 开发模式,提供了用户无感的 SSR 开发
|
|
30
30
|
不过,开发者仍然需要关注数据的兜底处理,例如 `null` 值或不符合预期的数据返回。避免在 SSR 时产生 React 渲染错误或是返回凌乱的渲染结果。
|
31
31
|
|
32
32
|
:::info 补充信息
|
33
|
-
|
33
|
+
更多相关内容可以查看[数据获取](/docs/guides/basic-features/data-fetch)。
|
34
34
|
:::
|
35
35
|
|
36
36
|
## 保持渲染一致
|
37
37
|
|
38
|
-
|
38
|
+
有些业务中,通常需要根据当前的运行容器环境特征做不同的 UI 展示,例如 [UA](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) 信息。如果处理不够仔细,此时很有可能出现不符合预期的渲染结果。
|
39
39
|
|
40
|
-
这里通过一个例子,演示当 SSR 与 CSR
|
41
|
-
|
42
|
-
在组件中添加以下代码:
|
40
|
+
这里通过一个例子,演示当 SSR 与 CSR 渲染不一致时出现的问题,在组件中添加以下代码:
|
43
41
|
|
44
42
|
```tsx
|
45
43
|
{
|
@@ -57,7 +55,7 @@ Modern.js 打破传统的 SSR 开发模式,提供了用户无感的 SSR 开发
|
|
57
55
|
Warning: Expected server HTML to contain a matching <div> in <div>.
|
58
56
|
```
|
59
57
|
|
60
|
-
|
58
|
+
这是 React 在客户端执行注水逻辑时,发现渲染结果与 SSR 渲染结果不一致造成的。虽然页面表现正常,但在复杂应用中,很有可能因此出现 DOM 层级混乱、样式混乱等问题。
|
61
59
|
|
62
60
|
:::info 注
|
63
61
|
关于注水逻辑请参考[这里](https://reactjs.org/docs/react-dom.html#hydrate)。
|
@@ -184,3 +182,68 @@ import { PreRender } from '@modern-js/runtime/ssr';
|
|
184
182
|
:::info 补充信息
|
185
183
|
`PreRender` 的详细使用可以参考[这里](/docs/apis/app/runtime/ssr/pre-render)。
|
186
184
|
:::
|
185
|
+
|
186
|
+
## Treeshaking
|
187
|
+
|
188
|
+
开启 SSR 时,Modern.js 会用相同的入口,构建出 SSR Bundle 和 CSR Bundle 两份产物。因此,在 SSR Bundle 中存在 Web API,或是在 CSR Bundle 中存在 Node API 时,都可能导致运行出错。
|
189
|
+
|
190
|
+
### 环境变量区分
|
191
|
+
|
192
|
+
在组件中可以直接使用 Modern.js 内置的环境变量 `MODERN_TARGET` 进行判断,方便在构建时删除无用代码:
|
193
|
+
|
194
|
+
```ts
|
195
|
+
export default () => {
|
196
|
+
if (process.env.MODERN_TARGET === 'node') {
|
197
|
+
console.log('server render');
|
198
|
+
} else {
|
199
|
+
console.log('client render');
|
200
|
+
}
|
201
|
+
}
|
202
|
+
```
|
203
|
+
|
204
|
+
:::note
|
205
|
+
更多内容可以查看[环境变量](/docs/guides/basic-features/env-vars)。
|
206
|
+
:::
|
207
|
+
|
208
|
+
### 文件后缀区分
|
209
|
+
|
210
|
+
但有时,这种 Treeshaking 的方式并不能保证代码被完全分离。EdenX 也支持通过 `.node.` 后缀的文件来区分 SSR Bundle 和 CSR Bundle 产物的打包文件。
|
211
|
+
|
212
|
+
例如存在 `client-sdk` 中直接使用了 Web API:
|
213
|
+
|
214
|
+
```ts
|
215
|
+
// client-sdk
|
216
|
+
export const href = location.href;
|
217
|
+
```
|
218
|
+
|
219
|
+
这时候直接引用到组件中,会造成 SSR 报错。可以创建同名的 `.ts` 和 `.node.ts` 文件做一层代理:
|
220
|
+
|
221
|
+
```ts title="compat.ts"
|
222
|
+
export { href } from 'client-sdk';
|
223
|
+
```
|
224
|
+
|
225
|
+
```ts title="compat.node.ts"
|
226
|
+
export const href = '';
|
227
|
+
```
|
228
|
+
|
229
|
+
在文件中直接引入 `./compat`,此时 SSR 环境下会优先使用 `.node.ts` 后缀的文件,CSR 环境下会使用 `.ts` 后缀的文件。
|
230
|
+
|
231
|
+
```ts title="App.tsx"
|
232
|
+
import { href } from './compat'
|
233
|
+
|
234
|
+
export default () => {
|
235
|
+
return <div onClick={() => { console.log(href) }}></div>
|
236
|
+
}
|
237
|
+
```
|
238
|
+
|
239
|
+
### 独立文件
|
240
|
+
|
241
|
+
上述两种方式,都会为开发者带来一些心智负担。Modern.js 正在基于[嵌套路由](/docs/guides/basic-features/routes)开发设计[更简单的方案](/docs/guides/basic-features/data-fetch)来分离 CSR 和 SSR 的代码。
|
242
|
+
|
243
|
+
## 接口请求
|
244
|
+
|
245
|
+
在 SSR 中发起接口请求时,开发者有时自己封装了同构的请求工具。部分接口需要传递用户 Cookie,开发者可以通过 [`useRuntimeContext`](/docs/guides/basic-features/data-fetch#route-loader) API 获取到请求头来实现。
|
246
|
+
|
247
|
+
需要注意的是,此时获取到的是 HTML 请求的请求头,不一定适用于接口请求,因此**千万不能**透传所有请求头。并且,一些后端接口,或是通用网关,会根据请求头中的信息做校验,全量透传容易出现各种难以排查的问题,推荐**按需透传**。
|
248
|
+
|
249
|
+
如果实在需要透传所有请求头,请务必过滤 `host` 字段。
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
title: 构建能力
|
3
|
+
sidebar_position: 2
|
4
|
+
---
|
5
|
+
|
6
|
+
**Modern.js 的构建能力由 [Modern.js Builder](https://modernjs.dev/builder) 提供。**
|
7
|
+
|
8
|
+
Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向现代 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和 rspack 等多种打包工具,默认情况下使用最成熟的 webpack 进行打包。
|
9
|
+
|
10
|
+
## 构建架构
|
11
|
+
|
12
|
+
从构建的角度看,Modern.js 分为三层架构,从上到下依次是:
|
13
|
+
|
14
|
+
- 上层研发框架:Modern.js。
|
15
|
+
- 通用构建引擎:Modern.js Builder。
|
16
|
+
- 底层打包工具:webpack 和 rspack。
|
17
|
+
|
18
|
+
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/builder-layers-1117.png" style={{ maxWidth: '540px' }} />
|
19
|
+
|
20
|
+
## 构建文档
|
21
|
+
|
22
|
+
由于 Modern.js Builder 是一个可独立使用的模块,我们为它提供了单独的文档,文档地址为:[modernjs.dev/builder](https://modernjs.dev/builder)。
|
23
|
+
|
24
|
+
在该文档中,你可以了解到 Modern.js Builder 的详细介绍,同时也可以找到各个构建能力的完整使用指南。当你遇到构建方面的需求或问题时,建议你优先阅读 Modern.js Builder 文档来解决。
|
25
|
+
|
26
|
+
## 构建配置
|
27
|
+
|
28
|
+
Modern.js 的配置继承自 Modern.js Builder,因此你可以在 Modern.js 中使用 Modern.js Builder 提供的所有构建配置。
|
29
|
+
|
30
|
+
以 Modern.js Builder 的 `html.title` 配置项为例,你可以直接在 `modern.config.ts` 文件中使用该配置项,它会被自动传递给 Modern.js Builder。
|
31
|
+
|
32
|
+
```ts title="modern.config.js"
|
33
|
+
export default defineConfig({
|
34
|
+
html: {
|
35
|
+
title: 'example',
|
36
|
+
},
|
37
|
+
});
|
38
|
+
```
|
39
|
+
|
40
|
+
关于构建配置的详细说明,请参考 [「Modern.js Builder - Builder 配置」](https://modernjs.dev/builder/zh/guide/basic/builder-config.html)。
|
41
|
+
|
42
|
+
## 构建能力
|
43
|
+
|
44
|
+
Modern.js Builder 提供了丰富的构建能力,包括 JavaScript 编译、CSS 编译、静态资源处理、代码热更新、代码压缩、TS 类型检查等几十种能力。
|
45
|
+
|
46
|
+
我们推荐你阅读 [「Modern.js Builder - 功能导航」](https://modernjs.dev/builder/zh/guide/features.html) 来了解 Modern.js Builder 提供的所有构建能力。
|
@@ -4,20 +4,7 @@ sidebar_position: 4
|
|
4
4
|
|
5
5
|
# Less 和 Sass
|
6
6
|
|
7
|
-
[Less](https://lesscss.org/) 和 [Sass](https://sass-lang.com/) 是常用的两种 CSS 预处理器,Modern.js
|
8
|
-
|
9
|
-
## 启用 Less 或 Sass
|
10
|
-
|
11
|
-
为了使用 Less 或 Sass 编译能力,我们需要先启用对应的功能。
|
12
|
-
|
13
|
-
以 Less 为例,在当前项目根目录执行 new 命令, 并选择 **启用 Less 支持** 即可。
|
14
|
-
|
15
|
-
```bash
|
16
|
-
$ pnpm run new
|
17
|
-
? 请选择你想要的操作
|
18
|
-
? 启用可选功能 (Use arrow keys)
|
19
|
-
❯ 启用 Less 支持
|
20
|
-
```
|
7
|
+
[Less](https://lesscss.org/) 和 [Sass](https://sass-lang.com/) 是常用的两种 CSS 预处理器,Modern.js 内置了 Less 和 Sass 编译能力的支持。
|
21
8
|
|
22
9
|
## 自定义配置
|
23
10
|
|
@@ -23,6 +23,40 @@ Modern.js 提供了对环境变量的支持,包含内置的环境变量和自
|
|
23
23
|
MODERN_ENV 的优先级高于 NODE_ENV。
|
24
24
|
:::
|
25
25
|
|
26
|
+
### MODERN_TARGET
|
27
|
+
|
28
|
+
使用 `@modern-js/runtime` 时会自动注入,用于区分 SSR 与 CSR 环境。开发者可以自行在代码中判断,构建时会默认移除 dead code。
|
29
|
+
|
30
|
+
```ts title="App.tsx"
|
31
|
+
function App() {
|
32
|
+
if (process.env.MODERN_TARGET === 'browser') {
|
33
|
+
console.log(window.innerHeight);
|
34
|
+
};
|
35
|
+
};
|
36
|
+
```
|
37
|
+
|
38
|
+
开发环境打包后,可以看到 SSR 产物和 CSR 产物如下:
|
39
|
+
|
40
|
+
```js title="dist/bundles/main.js"
|
41
|
+
function App() {
|
42
|
+
if (false) {}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
```js title="dist/static/main.js"
|
47
|
+
function App() {
|
48
|
+
if (true) {
|
49
|
+
console.log(window.innerHeight);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
54
|
+
:::note
|
55
|
+
在生产环境,会将 dead code 移除,例如上述 `if` 语句。
|
56
|
+
:::
|
57
|
+
|
58
|
+
这种方式可以针对不同客户端提供不同的产物,保证代码体积最小化。也能方便处理不同环境下,代码中的一些副作用,
|
59
|
+
|
26
60
|
## 自定义环境变量
|
27
61
|
|
28
62
|
环境变量支持通过 `shell` 和 `.env` 文件两种方式指定。
|
@@ -3,7 +3,7 @@ title: 路由
|
|
3
3
|
sidebar_position: 1
|
4
4
|
---
|
5
5
|
|
6
|
-
Modern.js 内置了对 [React Router 6](https://reactrouter.com/en/main) 的**部分**支持,并提供了多种类型的路由模式。根据不同[入口](/docs/guides/concept/entries)
|
6
|
+
Modern.js 内置了对 [React Router 6](https://reactrouter.com/en/main) 的**部分**支持,并提供了多种类型的路由模式。根据不同[入口](/docs/guides/concept/entries)类型,将路由分为三种模式,分别是**约定式路由**,**自控式路由**和**其他路由方案**。
|
7
7
|
|
8
8
|
:::note
|
9
9
|
本小节提到的路由,都是客户端路由,即 SPA 路由。
|
@@ -219,40 +219,21 @@ export default const ErrorBoundary = () => {
|
|
219
219
|
|
220
220
|
## 自控式路由
|
221
221
|
|
222
|
-
以 `
|
223
|
-
|
224
|
-
例如:
|
222
|
+
以 `src/App.tsx` 为约定的入口,Modern.js 不会多路由做额外的操作,开发者可以自行使用 React Router 6 的 API 进行开发,例如:
|
225
223
|
|
226
224
|
```tsx
|
227
|
-
import {
|
228
|
-
|
229
|
-
Routes,
|
230
|
-
BrowserRouter,
|
231
|
-
Outlet,
|
232
|
-
} from '@modern-js/runtime/router';
|
225
|
+
import { Route, Routes, BrowserRouter } from '@modern-js/runtime/router';
|
226
|
+
import { StaticRouter } from '@modern-js/runtime/router/server';
|
233
227
|
|
228
|
+
const Router = typeof window === 'undefined' ? StaticRouter : BrowserRouter;
|
234
229
|
export default () => {
|
235
230
|
return (
|
236
|
-
<
|
237
|
-
<
|
238
|
-
<
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
element={
|
243
|
-
<div>
|
244
|
-
User Layout
|
245
|
-
<Outlet />
|
246
|
-
</div>
|
247
|
-
}
|
248
|
-
>
|
249
|
-
<Route index element={<div>user</div>} />
|
250
|
-
<Route path="profile" element={<div>profile</div>} />
|
251
|
-
</Route>
|
252
|
-
<Route path="about" element={<div>about</div>} />
|
253
|
-
</Routes>
|
254
|
-
</BrowserRouter>
|
255
|
-
</div>
|
231
|
+
<Router location={context.request.pathname}>
|
232
|
+
<Routes>
|
233
|
+
<Route index element={<div>index</div>} />
|
234
|
+
<Route path="about" element={<div>about</div>} />
|
235
|
+
</Routes>
|
236
|
+
</Router>
|
256
237
|
);
|
257
238
|
};
|
258
239
|
```
|
@@ -261,11 +242,27 @@ export default () => {
|
|
261
242
|
在自控式路由下,开发者如果希望在 SSR 中使用 React Router 6 中 [Loader API](https://reactrouter.com/en/main/hooks/use-loader-data#useloaderdata) 的能力会相对复杂,推荐直接使用约定式路由。Modern.js 已经为你封装好了一切。
|
262
243
|
|
263
244
|
<!-- Todo 嵌套路由带来的优化可以补充下文档-->
|
264
|
-
如果项目只想升级到 React Router 6,而不希望使用嵌套路由带来的优化,那[useLoader](/docs/apis/app/runtime/core/use-loader) 在 SSR 下仍然可以工作。
|
245
|
+
如果项目只想升级到 React Router 6,而不希望使用嵌套路由带来的优化,那 [useLoader](/docs/apis/app/runtime/core/use-loader) 在 SSR 下仍然可以工作。
|
265
246
|
:::
|
266
247
|
|
267
|
-
##
|
248
|
+
## 其他路由方案
|
268
249
|
|
269
|
-
|
270
|
-
|
271
|
-
|
250
|
+
默认情况下,Modern.js 会开启内置的路由方案,即 React Router。
|
251
|
+
|
252
|
+
```js
|
253
|
+
export default defineConfig({
|
254
|
+
runtime: {
|
255
|
+
router: true,
|
256
|
+
}
|
257
|
+
})
|
258
|
+
```
|
259
|
+
|
260
|
+
Modern.js 从 `@modern-js/runtime/router` 命名空间暴露了 React Router 的 API 供开发者使用,保证开发者和 Modern.js 中使用同一份代码。另外,这种情况下,React Router 的代码会被打包到 JS 产物中。如果项目已经有自己的路由方案,或者不需要使用客户端路由,可以关闭这个功能。
|
261
|
+
|
262
|
+
```js
|
263
|
+
export default defineConfig({
|
264
|
+
runtime: {
|
265
|
+
router: false,
|
266
|
+
}
|
267
|
+
})
|
268
|
+
```
|
@@ -91,13 +91,13 @@ Modern.js 会将和 `package.json` 中 `name` 同名的目录作为主入口,
|
|
91
91
|
|
92
92
|
如果入口为 `routes/` 约定,Modern.js 会在启动时扫描 `routes` 下的文件,基于文件约定,自动生成客户端路由(react-router)。
|
93
93
|
|
94
|
-
详细内容可以参考[路由](/docs/guides/basic-features/routes)
|
94
|
+
详细内容可以参考[路由](/docs/guides/basic-features/routes)。
|
95
95
|
|
96
96
|
### App 入口
|
97
97
|
|
98
98
|
如果入口为 `App.[jt]sx?` 约定,开发者可以在这个文件中自由的设置客户端路由,或者不设置客户端路由。
|
99
99
|
|
100
|
-
详细内容可以参考[路由](/docs/guides/basic-features/routes)
|
100
|
+
详细内容可以参考[路由](/docs/guides/basic-features/routes)。
|
101
101
|
|
102
102
|
### Index 入口
|
103
103
|
|
@@ -105,12 +105,12 @@ Modern.js 会将和 `package.json` 中 `name` 同名的目录作为主入口,
|
|
105
105
|
|
106
106
|
如果入口为 `index.[jt]sx?` 约定,Modern.js 会根据该文件是否存在默认的组件导出,来决定构建行为。
|
107
107
|
|
108
|
-
详细内容可以参考[自定义 App](/docs/guides/advanced-features/custom-app)
|
108
|
+
详细内容可以参考[自定义 App](/docs/guides/advanced-features/custom-app)。
|
109
109
|
|
110
110
|
## 配置入口
|
111
111
|
|
112
112
|
在 Modern.js 中,除了使用文件约定生成入口外,还可以在 `modern.config.[jt]s` 中手动配置入口。
|
113
113
|
|
114
114
|
:::tip
|
115
|
-
详情可以查看 [source.entries](/docs/configure/app/source/entries)
|
115
|
+
详情可以查看 [source.entries](/docs/configure/app/source/entries)。
|
116
116
|
:::
|
@@ -1,10 +1,9 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
title: 扩展插件 Hook
|
3
|
+
sidebar_position: 5
|
3
4
|
---
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
本章节介绍如何通过动态注册 [Hook 模型](/docs/apis/app/runtime/plugin/hook#hook-模型) 的方式来扩展插件 Hook。
|
6
|
+
本小节介绍如何通过动态注册 [Hook 模型](/docs/guides/topic-detail/framework-plugin/hook) 的方式来扩展插件 Hook。
|
8
7
|
|
9
8
|
## 示例
|
10
9
|
|