@modern-js/main-doc 2.0.0-beta.1 → 2.0.0-beta.3
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/en/docusaurus-plugin-content-docs/current/apis/app/commands/build.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/lint.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +1 -4
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/commands/test.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +1 -1
- 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/auto-actions.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/connect.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +2 -2
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-store.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/handle-effect.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/model_.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-local-model.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-model.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-static-model.md +1 -1
- package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +1 -23
- package/en/docusaurus-plugin-content-docs/current/components/command-tip.md +56 -0
- package/en/docusaurus-plugin-content-docs/current/components/reduck-migration.md +1 -0
- package/en/docusaurus-plugin-content-docs/current/components/reduck-tip.md +5 -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 +12 -0
- 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/runtime/router.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/guides/topic-detail/generator/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/app.md +152 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/ejs.md +56 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/fs.md +54 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/git.md +49 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/handlebars.md +58 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/json.md +59 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/npm.md +49 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/develop.md +52 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/introduce.md +46 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/run-in-js.md +48 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/structure.md +87 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/common.md +106 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/module.md +39 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/monorepo.md +28 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/mwa.md +89 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/abstract.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addFile.md +52 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addHelper.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addManyFile.md +58 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addPartial.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/introduce.md +38 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/rmDir.md +24 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/rmFile.md +24 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateJSONFile.md +54 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateModernConfig.md +26 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.md +33 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.md +20 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/initGitRepo.md +16 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/isInGitRepo.md +16 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/afterForged.md +35 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/onForged.md +36 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/isFileExit.md +22 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/locale.md +17 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/readDir.md +22 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/addInputAfter.md +57 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/addInputBefore.md +56 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/setInput.md +42 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/setInputValue.md +30 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/type.md +65 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/introduce.md +91 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/createElement.md +33 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/createSubProject.md +35 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/enableFunc.md +44 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/introduce.md +15 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/npm/_category_.json +4 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/npm/install.md +18 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/develop.md +125 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/use.md +61 -0
- package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/project.md +118 -0
- package/en/docusaurus-plugin-content-docs/current.json +57 -21
- package/package.json +3 -3
- package/scripts/config.ts +2 -2
- package/scripts/summary.en.json +1 -1
- package/scripts/summary.zh.json +1 -1
- package/zh/apis/app/commands/new.md +0 -3
- package/zh/apis/app/hooks/server/test.md +2 -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/apis/app/runtime/web-server/hook.md +4 -4
- package/zh/apis/app/runtime/web-server/middleware.md +4 -4
- 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 +12 -0
- 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/bff/_category_.json +5 -1
- package/zh/guides/advanced-features/bff/bff-proxy.md +5 -3
- package/zh/guides/advanced-features/bff/frameworks.md +72 -51
- package/zh/guides/advanced-features/bff/function.md +16 -30
- package/zh/guides/advanced-features/bff/index.md +20 -0
- package/zh/guides/advanced-features/bff/type.md +43 -0
- package/zh/guides/advanced-features/custom-app.md +69 -1
- package/zh/guides/advanced-features/ssg.md +74 -63
- package/zh/guides/advanced-features/ssr.md +74 -11
- package/zh/guides/advanced-features/web-server.md +21 -110
- 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 +62 -1
- package/zh/guides/basic-features/env-vars.md +122 -41
- package/zh/guides/basic-features/routes.md +264 -0
- package/zh/guides/concept/entries.md +112 -0
- package/zh/guides/concept/lifecycle.md +10 -0
- package/zh/guides/get-started/quick-start.md +199 -1
- package/zh/guides/get-started/upgrade.md +75 -1
- 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/generator/codesmith/api/_category_.json +4 -0
- package/zh/guides/topic-detail/generator/codesmith/api/app.md +152 -0
- package/zh/guides/topic-detail/generator/codesmith/api/ejs.md +56 -0
- package/zh/guides/topic-detail/generator/codesmith/api/fs.md +54 -0
- package/zh/guides/topic-detail/generator/codesmith/api/git.md +48 -0
- package/zh/guides/topic-detail/generator/codesmith/api/handlebars.md +56 -0
- package/zh/guides/topic-detail/generator/codesmith/api/json.md +58 -0
- package/zh/guides/topic-detail/generator/codesmith/api/npm.md +45 -0
- package/zh/guides/topic-detail/generator/codesmith/develop.md +52 -0
- package/zh/guides/topic-detail/generator/codesmith/introduce.md +42 -1
- package/zh/guides/topic-detail/generator/codesmith/run-in-js.md +48 -0
- package/zh/guides/topic-detail/generator/codesmith/structure.md +86 -0
- package/zh/guides/topic-detail/generator/config/mwa.md +4 -8
- package/zh/guides/topic-detail/generator/plugin/api/file/addFile.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/file/addHelper.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/file/addPartial.md +2 -2
- package/zh/guides/topic-detail/generator/plugin/api/file/introduce.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/file/rmDir.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/file/rmFile.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.md +3 -2
- package/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.md +2 -2
- package/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.md +3 -3
- package/zh/guides/topic-detail/generator/plugin/api/hook/onForged.md +3 -3
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/input/type.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/createElement.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/npm/install.md +1 -1
- package/zh/guides/topic-detail/generator/plugin/develop.md +11 -7
- package/zh/guides/topic-detail/model/quick-start.md +4 -0
- package/zh/guides/topic-detail/monorepo/sub-project-interface.md +0 -2
- package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +2 -2
- 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.1-generator.md +0 -8
- package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +12 -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 +24 -19
- package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +31 -35
- 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/env.md +0 -72
- 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/env.md +0 -70
- 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/components/deploy.md +0 -60
- package/zh/components/dev-ide.md +0 -1
- package/zh/components/entry-name.md +0 -15
- package/zh/components/env-prepare.md +0 -1
- package/zh/components/launch-bff-choices.md +0 -6
- package/zh/guides/advanced-features/bff/bff-server.md +0 -142
- package/zh/guides/advanced-features/typescript.md +0 -4
- package/zh/guides/basic-features/image.md +0 -43
- package/zh/guides/concept/integrated.md +0 -4
- package/zh/guides/concept/solutions.md +0 -4
- 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 -318
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: 静态站点生成(SSG)
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -9,11 +9,11 @@ SSG(Static Site Generation)是一种基于数据与模板,在构建时渲
|
|
|
9
9
|
SSG 是构建阶段的解决方案,因此仅对生产环境有效。通过 `dev` 命令运行时,表现效果与 SSR 相同。
|
|
10
10
|
:::
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
我们首先需要执行 `pnpm run new` 启用 SSG 功能:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
?
|
|
16
|
-
?
|
|
15
|
+
? 请选择你想要的操作: 启用可选功能
|
|
16
|
+
? 启用可选功能: 启用「SSG」功能
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
SSG 在**约定式路由**和**自控式路由**下的使用方式不同。
|
|
@@ -25,22 +25,37 @@ SSG 在**约定式路由**和**自控式路由**下的使用方式不同。
|
|
|
25
25
|
例如,以下是一个使用约定式路由的项目目录结构:
|
|
26
26
|
|
|
27
27
|
```
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
│
|
|
31
|
-
│
|
|
32
|
-
│
|
|
28
|
+
.
|
|
29
|
+
├── src
|
|
30
|
+
│ └── routes
|
|
31
|
+
│ ├── layout.tsx
|
|
32
|
+
│ ├── page.tsx
|
|
33
|
+
│ └── user
|
|
34
|
+
│ ├── layout.tsx
|
|
35
|
+
│ ├── page.tsx
|
|
36
|
+
│ └── profile
|
|
37
|
+
│ └── page.tsx
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
上述文件目录将会生成以下三条路由:
|
|
41
|
+
|
|
42
|
+
- `/`
|
|
43
|
+
- `/user`
|
|
44
|
+
- `/user/profile`
|
|
45
|
+
|
|
46
|
+
:::note
|
|
47
|
+
如果还不了解约定式路由的规则,可以先查看[路由](/docs/guides/basic-features/routes)。
|
|
48
|
+
:::
|
|
49
|
+
|
|
50
|
+
在 `src/routes/page.tsx` 中添加组件代码:
|
|
36
51
|
|
|
37
52
|
```jsx title="src/pages/index.tsx"
|
|
38
53
|
export default () => {
|
|
39
|
-
return <div>
|
|
54
|
+
return <div>Index Page</div>
|
|
40
55
|
}
|
|
41
56
|
```
|
|
42
57
|
|
|
43
|
-
SSG
|
|
58
|
+
SSG 也是在 Node.js 环境渲染页面,因此我们可以在**开发阶段开启 SSR**,提前在暴露代码问题,验证 SSG 渲染效果:
|
|
44
59
|
|
|
45
60
|
```typescript title="modern.config.ts"
|
|
46
61
|
export default defineConfig({
|
|
@@ -50,13 +65,11 @@ export default defineConfig({
|
|
|
50
65
|
}
|
|
51
66
|
```
|
|
52
67
|
|
|
53
|
-
在项目根路径下执行 `pnpm run dev` 命令,查看 `dist/` 目录,此时只生成一个 HTML
|
|
54
|
-
|
|
55
|
-

|
|
68
|
+
在项目根路径下执行 `pnpm run dev` 命令,查看 `dist/` 目录,此时只生成一个 HTML 文件 `main/index.html`。
|
|
56
69
|
|
|
57
|
-
在项目根路径下执行 `pnpm run build` 命令,构建完成后,查看 `dist/` 目录,此时生成 `main/index.html`、`main/
|
|
70
|
+
在项目根路径下执行 `pnpm run build` 命令,构建完成后,查看 `dist/` 目录,此时生成 `main/index.html`、`main/user/index.html` 和 `main/user/profile/index.html` 三个 HTML 文件,内容分别对应上述三条路由。
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
**约定式路由**中的每一条路由,都会生成一个单独的 HTML 文件。查看 `main/index.html`,可以发现包含 `Index Page` 的文本内容,这正是 SSG 的效果。
|
|
60
73
|
|
|
61
74
|
执行 `pnpm run start` 启动项目后,访问页面,在浏览器我们工具的 Network 窗口,查看请求返回的文档,文档包含组件渲染后的完整页面内容。
|
|
62
75
|
|
|
@@ -64,45 +77,46 @@ export default defineConfig({
|
|
|
64
77
|
|
|
65
78
|
**自控式路由**是通过组件代码自定义路由,需要应用运行起来才能获取准确的路由信息。因此,无法开箱即用的使用 SSG 功能。此时需要用户提前告知 Modern.js 框架,哪些路由需要开启 SSG 功能。
|
|
66
79
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
import {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<Switch>
|
|
74
|
-
<Route path="/" exact={true}>
|
|
75
|
-
<div>Home</div>
|
|
76
|
-
</Route>
|
|
77
|
-
<Route path="/foo" exact={true}>
|
|
78
|
-
<div>Foo</div>
|
|
79
|
-
</Route>
|
|
80
|
-
</Switch>
|
|
81
|
-
);
|
|
82
|
-
```
|
|
80
|
+
例如有以下代码,包含多条路由,设置 `output.ssg` 为 `true` 时,默认只会渲染入口路由即 `/`:
|
|
81
|
+
|
|
82
|
+
```tsx title="src/App.tsx"
|
|
83
|
+
import { useRuntimeContext } from '@modern-js/runtime';
|
|
84
|
+
import { Routes, Route, BrowserRouter } from '@modern-js/runtime/router';
|
|
85
|
+
import { StaticRouter } from '@modern-js/runtime/router/server';
|
|
83
86
|
|
|
84
|
-
|
|
87
|
+
const Router = typeof window === 'undefined' ? StaticRouter : BrowserRouter;
|
|
88
|
+
|
|
89
|
+
export default () => {
|
|
90
|
+
const { context } = useRuntimeContext();
|
|
91
|
+
return (
|
|
92
|
+
<Router location={context.request.pathname}>
|
|
93
|
+
<Routes>
|
|
94
|
+
<Route index element={<div>index</div>} />
|
|
95
|
+
<Route path="about" element={<div>about</div>} />
|
|
96
|
+
</Routes>
|
|
97
|
+
</Router>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
```
|
|
85
101
|
|
|
86
|
-
|
|
102
|
+
如果我们希望同时开启 `/about` 的 SSG 功能,可以配置 `output.ssg`,告知 Modern.js 开启指定路由的 SSG 功能。
|
|
87
103
|
|
|
88
104
|
```typescript title="modern.config.ts"
|
|
89
105
|
export default defineConfig({
|
|
90
106
|
output: {
|
|
91
107
|
ssg: {
|
|
92
|
-
routes: ['/', '/
|
|
108
|
+
routes: ['/', '/about'],
|
|
93
109
|
},
|
|
94
110
|
},
|
|
95
111
|
})
|
|
96
112
|
```
|
|
97
113
|
|
|
98
|
-
执行 `pnpm run build` 与 `pnpm run start` 后,访问 `http://localhost:8080/
|
|
99
|
-
|
|
100
|
-
查看构建产物文件,可以看到 `dist/` 目录中,在默认的 `main` 入口产物目录下,新增一个 `foo.html` 文件:
|
|
114
|
+
执行 `pnpm run build` 与 `pnpm run start` 后,访问 `http://localhost:8080/about`,在 Preview 视图中可以看到页面已经完成渲染。
|
|
101
115
|
|
|
102
|
-
|
|
116
|
+
查看构建产物文件,可以看到 `dist/` 目录中,新增了一个 `main/about/index.html` 文件。
|
|
103
117
|
|
|
104
118
|
:::info
|
|
105
|
-
|
|
119
|
+
以上仅介绍了单入口的情况,更多相关内容可以查看 [API 文档](/docs/configure/app/output/ssg)。
|
|
106
120
|
:::
|
|
107
121
|
|
|
108
122
|
### 获取数据
|
|
@@ -116,36 +130,33 @@ export default defineConfig({
|
|
|
116
130
|
- 在开发阶段,不管 `useLoader` 是否配置 `{ static: true }`,函数都会在 SSR 时获取数据。
|
|
117
131
|
:::
|
|
118
132
|
|
|
119
|
-
修改上述 `App.ts` 的代码为:
|
|
133
|
+
修改上述 `src/App.ts` 的代码为:
|
|
120
134
|
|
|
121
|
-
```
|
|
122
|
-
import {
|
|
123
|
-
import {
|
|
135
|
+
```tsx title="App.ts"
|
|
136
|
+
import { useRuntimeContext, useStaticLoader } from '@modern-js/runtime';
|
|
137
|
+
import { Routes, Route, BrowserRouter } from '@modern-js/runtime/router';
|
|
138
|
+
import { StaticRouter } from '@modern-js/runtime/router/server';
|
|
139
|
+
|
|
140
|
+
const Router = typeof window === 'undefined' ? StaticRouter : BrowserRouter;
|
|
124
141
|
|
|
125
142
|
export default () => {
|
|
126
|
-
const {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
static: true,
|
|
132
|
-
params: 'foo',
|
|
133
|
-
},
|
|
134
|
-
);
|
|
143
|
+
const { context } = useRuntimeContext();
|
|
144
|
+
|
|
145
|
+
const { data } = useStaticLoader(async () => ({
|
|
146
|
+
message: Math.random(),
|
|
147
|
+
}));
|
|
135
148
|
|
|
136
149
|
return (
|
|
137
|
-
<
|
|
138
|
-
<
|
|
139
|
-
<div>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
</Route>
|
|
144
|
-
</Switch>
|
|
150
|
+
<Router location={context.request.pathname}>
|
|
151
|
+
<Routes>
|
|
152
|
+
<Route index element={<div>index</div>} />
|
|
153
|
+
<Route path="about" element={<div>about, {data?.message}</div>} />
|
|
154
|
+
</Routes>
|
|
155
|
+
</Router>
|
|
145
156
|
);
|
|
146
157
|
};
|
|
147
158
|
```
|
|
148
159
|
|
|
149
160
|
执行 `pnpm run dev`,重复刷新页面,可以看到 `/foo` 页面的渲染结果不断发生变化,说明数据是在请求时获取的。
|
|
150
161
|
|
|
151
|
-
重新执行 `pnpm run build` 后,执行 `pnpm run start
|
|
162
|
+
重新执行 `pnpm run build` 后,执行 `pnpm run start`,重复刷新页面,发现页面渲染结果始终保持同样的内容,数据在请求时不会再次获取,说明页面在编译时已经完成渲染。
|
|
@@ -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` 字段。
|
|
@@ -1,135 +1,46 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
2
|
+
title: 自定义 Web Server
|
|
3
3
|
sidebar_position: 2
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Modern.js 作为以客户端为中心的开发框架,对服务端的定制能力较弱。而在有些开发场景下,需要定制特殊的服务端逻辑,例如用户鉴权、请求预处理、添加页面渲染骨架等。
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
因此 Modern.js 提供了一种功能,让项目可以在给定的范围内扩展 Modern.js 内置的 Web Server,来实现相应的需求。
|
|
9
9
|
|
|
10
|
+
## 创建自定义 Web Server
|
|
10
11
|
|
|
11
|
-
在项目根目录执行 `pnpm run new`
|
|
12
|
-
|
|
12
|
+
在项目根目录执行 `pnpm run new` 命令,按照如下选择,开启「自定义 Web Serve」功能:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
? 请选择你想要的操作: 创建工程元素
|
|
16
|
-
? 创建工程元素:
|
|
17
|
-
? 请选择运行时框架: Express/Koa/Egg/Nest
|
|
16
|
+
? 创建工程元素: 新建「自定义 Web Server」源码目录
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
目前 Modern.js 默认支持 4 种主流的 Node.js Server 框架:[Express](https://expressjs.com/)、[Koa](https://koajs.com/)、[Egg.js](https://eggjs.org/zh-cn/)、[Nest](https://nestjs.com/),选择运行时框架时,可根据自身偏好进行选择。
|
|
21
|
-
|
|
22
19
|
执行命令后,项目目录下会新建 `server/index.ts` 文件,自定义逻辑在这个文件中编写。
|
|
23
20
|
|
|
24
|
-
##
|
|
21
|
+
## 使用 API 扩展 Web Server
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
Modern.js 提供了 **Hook** 与 **Middleware** 两类 API 来扩展 Web Server。
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
目前 Modern.js 只支持前置中间件的扩展。
|
|
30
|
-
:::
|
|
25
|
+
### Hook
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```ts
|
|
35
|
-
import { hook } from '@modern-js/runtime/server';
|
|
36
|
-
import type { Request, Response, NextFunction } from 'express';
|
|
37
|
-
|
|
38
|
-
export default hook(({ addMiddleware }) => {
|
|
39
|
-
addMiddleware((request: Request, response: Response, next: NextFunction) => {
|
|
40
|
-
if (request.headers.cookies['login-token']) {
|
|
41
|
-
return next();
|
|
42
|
-
} else {
|
|
43
|
-
response.status = 401;
|
|
44
|
-
response.end();
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
```
|
|
27
|
+
Hook 可以控制 Web Server 对请求处理的内置逻辑,非 BFF 请求会经过 Hook 的处理。
|
|
49
28
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import { hook } from '@modern-js/runtime/server';
|
|
54
|
-
import type { Context, Next } from 'koa';
|
|
55
|
-
|
|
56
|
-
export default hook(({ addMiddleware }) => {
|
|
57
|
-
addMiddleware(async (ctx: Context, next: Next) => {
|
|
58
|
-
if (ctx.cookies['login-token']) {
|
|
59
|
-
await next();
|
|
60
|
-
} else {
|
|
61
|
-
ctx.status = 401;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
```
|
|
29
|
+
Hook 不可以使用运行时框架拓展。
|
|
66
30
|
|
|
67
|
-
|
|
31
|
+
详细 API 可以查看 [Hook](/docs/apis/app/runtime/web-server/hook)。
|
|
68
32
|
|
|
69
|
-
Egg 添加中间件的方式与 Koa 相同。
|
|
70
33
|
|
|
71
|
-
|
|
72
|
-
import { hook } from '@modern-js/runtime/server';
|
|
73
|
-
import type { Context, Next } from 'koa';
|
|
34
|
+
### Middleware
|
|
74
35
|
|
|
75
|
-
|
|
76
|
-
addMiddleware(async (ctx: Context, next: Next) => {
|
|
77
|
-
if (ctx.cookies['login-token']) {
|
|
78
|
-
await next();
|
|
79
|
-
} else {
|
|
80
|
-
ctx.status = 401;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
```
|
|
36
|
+
Middleware 可以为 Web Server 添加前置中间件,只有 SSR 请求会经过 Middleware 的处理。
|
|
85
37
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
import { hook } from '@modern-js/runtime/server';
|
|
94
|
-
import { Module, Injectable, Controller, Get } from '@nestjs/common';
|
|
95
|
-
|
|
96
|
-
@Controller('cats')
|
|
97
|
-
export class CatsController {
|
|
98
|
-
constructor(private readonly catsService: CatsService) {}
|
|
99
|
-
|
|
100
|
-
@Get()
|
|
101
|
-
getHello() {
|
|
102
|
-
return this.catsService.getHello();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@Injectable()
|
|
107
|
-
class CatsService {
|
|
108
|
-
getHello(): string {
|
|
109
|
-
return '<div>Hello world!</div>';;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@Module({
|
|
114
|
-
controllers: [CatsController],
|
|
115
|
-
providers: [CatsService],
|
|
116
|
-
})
|
|
117
|
-
class CatsModule {}
|
|
118
|
-
|
|
119
|
-
export default hook(({ addMiddleware }) => {
|
|
120
|
-
addMiddleware((request: Request, response: Response, next: NextFunction) => {
|
|
121
|
-
if (request.headers.cookies['login-token']) {
|
|
122
|
-
return next();
|
|
123
|
-
} else {
|
|
124
|
-
response.status = 401;
|
|
125
|
-
response.end();
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
addMiddleware(CatsModule);
|
|
130
|
-
});
|
|
131
|
-
```
|
|
38
|
+
Middleware 可以使用运行时框架拓展。
|
|
39
|
+
|
|
40
|
+
详细 API 可以查看 [Hook](/docs/apis/app/runtime/web-server/middleware)。
|
|
41
|
+
|
|
42
|
+
## 完全自定义的 Web Server
|
|
132
43
|
|
|
133
|
-
:::
|
|
134
|
-
|
|
44
|
+
:::note
|
|
45
|
+
敬请期待
|
|
135
46
|
:::
|
|
@@ -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
|
|
|
@@ -1,4 +1,65 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: 数据获取
|
|
3
|
-
sidebar_position:
|
|
3
|
+
sidebar_position: 3
|
|
4
4
|
---
|
|
5
|
+
|
|
6
|
+
Modern.js 中提供了开箱即用的数据获取能力,开发者可以通过这些 API,在 CSR 和 SSR 环境同构的进行开发。
|
|
7
|
+
|
|
8
|
+
需要注意的是,这些 API 并不帮助应用发起请求,而是帮助开发者更好的管理数据与路由的关系。
|
|
9
|
+
|
|
10
|
+
## useLoader(旧版)
|
|
11
|
+
|
|
12
|
+
**`useLoader`** 是 Modern.js 老版本中的 API。该 API 是一个 React Hook,专门提供给 SSR 应用使用,让开发者能同构的在组件中获取数据。
|
|
13
|
+
|
|
14
|
+
:::tip
|
|
15
|
+
CSR 的项目没有必要使用 `useLoader` 获取数据。
|
|
16
|
+
:::
|
|
17
|
+
|
|
18
|
+
以下是一个最简单的例子:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { useLoader } from '@modern-js/runtime';
|
|
22
|
+
|
|
23
|
+
export default () => {
|
|
24
|
+
const { data } = useLoader(async () => {
|
|
25
|
+
console.log('fetch in useLoader');
|
|
26
|
+
|
|
27
|
+
// 这里没有发送真实的请求,只是返回了一个写死的数据。
|
|
28
|
+
// 真实项目中,应该返回从远端获取的数据。
|
|
29
|
+
return {
|
|
30
|
+
name: 'modern.js',
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return <div>Hello, {data?.name}</div>;
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
上述代码启动后,访问页面。可以看到在终端输出了日志,而在浏览器终端却没有打印日志。
|
|
39
|
+
|
|
40
|
+
这是因为 Modern.js 在服务端渲染时,在会收集 `useLoader` 返回的数据,并将数据注入到响应的 HTML 中。如果 SSR 渲染成功,在 HTML 中可以看到如下代码片段:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<script>
|
|
44
|
+
window._SSR_DATA = {};
|
|
45
|
+
</script>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
在这全局变量中,记录了每一份数据,而在浏览器端渲染的过程中,会优先使用这份数据。如果数据不存在,则会重新执行 `useLoader` 函数。
|
|
49
|
+
|
|
50
|
+
:::note
|
|
51
|
+
在构建阶段,Modern.js 会自动为每个 `useLoader` 生成一个 Loader ID,并注入到 SSR 和 CSR 的 JS Bundle 中,用来关联 Loader 和数据。
|
|
52
|
+
:::
|
|
53
|
+
|
|
54
|
+
相比于 Next.js 中的 `getServerSideProps`,在渲染前预先获取数据。使用 `useLoader`,可以在组件中获取局部 UI 所需要的数据,而不用将数据层层传递。同样,也不会因为不同路由需要不同数据请求,而在最外层的数据获取函数中添加冗余的逻辑。当然 `useLoader` 也存在一些问题,例如服务端代码 Treeshaking 困难,服务端需要多一次预渲染等。
|
|
55
|
+
|
|
56
|
+
Modern.js 在新版本中,设计了全新的 Loader 方案。新方案解决了这些问题,并能够配合**嵌套路由**,对页面性能做优化。
|
|
57
|
+
|
|
58
|
+
:::note
|
|
59
|
+
详细 API 可以查看 [useLoader](/docs/apis/app/runtime/core/use-loader)。
|
|
60
|
+
:::
|
|
61
|
+
## Route Loader
|
|
62
|
+
|
|
63
|
+
:::note
|
|
64
|
+
敬请期待
|
|
65
|
+
:::
|