@modern-js/main-doc 0.0.0-next-20221116121040
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/.eslintrc.js +12 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE +144 -0
- package/en/configure/app/dev/asset-prefix.md +13 -0
- package/en/configure/app/dev/hmr.md +13 -0
- package/en/configure/app/dev/https.md +13 -0
- package/en/configure/app/dev/port.md +13 -0
- package/en/configure/app/dev/progress-bar.md +13 -0
- package/en/configure/app/dev/start-url.md +13 -0
- package/en/configure/app/html/app-icon.md +13 -0
- package/en/configure/app/html/crossorigin.md +13 -0
- package/en/configure/app/html/disable-html-folder.md +13 -0
- package/en/configure/app/html/favicon-by-entries.md +13 -0
- package/en/configure/app/html/favicon.md +13 -0
- package/en/configure/app/html/inject-by-entries.md +13 -0
- package/en/configure/app/html/inject.md +13 -0
- package/en/configure/app/html/meta-by-entries.md +13 -0
- package/en/configure/app/html/meta.md +13 -0
- package/en/configure/app/html/mount-id.md +13 -0
- package/en/configure/app/html/template-by-entries.md +13 -0
- package/en/configure/app/html/template-parameters-by-entries.md +13 -0
- package/en/configure/app/html/template-parameters.md +13 -0
- package/en/configure/app/html/template.md +13 -0
- package/en/configure/app/html/title-by-entries.md +13 -0
- package/en/configure/app/html/title.md +13 -0
- package/en/configure/app/output/asset-prefix.md +13 -0
- package/en/configure/app/output/assets-retry.md +13 -0
- package/en/configure/app/output/charset.md +13 -0
- package/en/configure/app/output/clean-dist-path.md +13 -0
- package/en/configure/app/output/convert-to-rem.md +13 -0
- package/en/configure/app/output/copy.md +13 -0
- package/en/configure/app/output/css-module-local-ident-name.md +13 -0
- package/en/configure/app/output/data-uri-limit.md +13 -0
- package/en/configure/app/output/disable-css-module-extension.md +13 -0
- package/en/configure/app/output/disable-filename-hash.md +13 -0
- package/en/configure/app/output/disable-inline-runtime-chunk.md +13 -0
- package/en/configure/app/output/disable-minimize.md +13 -0
- package/en/configure/app/output/disable-source-map.md +13 -0
- package/en/configure/app/output/dist-path.md +13 -0
- package/en/configure/app/output/enable-asset-fallback.md +13 -0
- package/en/configure/app/output/enable-asset-manifest.md +13 -0
- package/en/configure/app/output/enable-css-module-tsdeclaration.md +13 -0
- package/en/configure/app/output/enable-inline-scripts.md +13 -0
- package/en/configure/app/output/enable-inline-styles.md +13 -0
- package/en/configure/app/output/enable-latest-decorators.md +13 -0
- package/en/configure/app/output/externals.md +13 -0
- package/en/configure/app/output/filename.md +13 -0
- package/en/configure/app/output/legal-comments.md +13 -0
- package/en/configure/app/output/override-browserslist.md +13 -0
- package/en/configure/app/output/polyfill.md +13 -0
- package/en/configure/app/output/svg-default-export.md +13 -0
- package/en/configure/app/performance/build-cache.md +13 -0
- package/en/configure/app/performance/bundle-analyze.md +13 -0
- package/en/configure/app/performance/chunk-split.md +13 -0
- package/en/configure/app/performance/print-file-size.md +13 -0
- package/en/configure/app/performance/profile.md +13 -0
- package/en/configure/app/performance/remove-console.md +13 -0
- package/en/configure/app/performance/remove-moment-locale.md +13 -0
- package/en/configure/app/security/sri.md +13 -0
- package/en/configure/app/source/alias.md +13 -0
- package/en/configure/app/source/compile-js-data-uri.md +13 -0
- package/en/configure/app/source/define.md +13 -0
- package/en/configure/app/source/global-vars.md +13 -0
- package/en/configure/app/source/include.md +13 -0
- package/en/configure/app/source/module-scopes.md +13 -0
- package/en/configure/app/source/pre-entry.md +13 -0
- package/en/configure/app/source/resolve-extension-prefix.md +13 -0
- package/en/configure/app/source/resolve-main-fields.md +13 -0
- package/en/configure/app/tools/autoprefixer.md +13 -0
- package/en/configure/app/tools/babel.md +13 -0
- package/en/configure/app/tools/css-extract.md +13 -0
- package/en/configure/app/tools/css-loader.md +13 -0
- package/en/configure/app/tools/dev-server.md +13 -0
- package/en/configure/app/tools/html-plugin.md +13 -0
- package/en/configure/app/tools/inspector.md +13 -0
- package/en/configure/app/tools/less.md +13 -0
- package/en/configure/app/tools/minify-css.md +13 -0
- package/en/configure/app/tools/postcss.md +13 -0
- package/en/configure/app/tools/pug.md +13 -0
- package/en/configure/app/tools/sass.md +13 -0
- package/en/configure/app/tools/style-loader.md +13 -0
- package/en/configure/app/tools/styled-components.md +13 -0
- package/en/configure/app/tools/terser.md +13 -0
- package/en/configure/app/tools/ts-checker.md +13 -0
- package/en/configure/app/tools/ts-loader.md +13 -0
- package/en/configure/app/tools/webpack-chain.md +13 -0
- package/en/configure/app/tools/webpack.md +13 -0
- package/en/tutorials/foundations/_category_.json +5 -0
- package/en/tutorials/foundations/basic.md +8 -0
- package/en/tutorials/foundations/introduction.md +43 -0
- package/package.json +30 -0
- package/scripts/gen-config.ts +60 -0
- package/scripts/sync.ts +36 -0
- package/tsconfig.json +7 -0
- package/zh/apis/app/commands/_category_.json +8 -0
- package/zh/apis/app/commands/build.md +44 -0
- package/zh/apis/app/commands/dev.md +31 -0
- package/zh/apis/app/commands/index.md +12 -0
- package/zh/apis/app/commands/inspect.md +39 -0
- package/zh/apis/app/commands/lint.md +22 -0
- package/zh/apis/app/commands/new.md +59 -0
- package/zh/apis/app/commands/start.md +32 -0
- package/zh/apis/app/commands/test.md +36 -0
- package/zh/apis/app/commands/upgrade.md +23 -0
- package/zh/apis/app/hooks/_category_.json +8 -0
- package/zh/apis/app/hooks/api/_category_.json +4 -0
- package/zh/apis/app/hooks/api/framework/_category_.json +4 -0
- package/zh/apis/app/hooks/api/framework/app.md +100 -0
- package/zh/apis/app/hooks/api/framework/lambda.md +79 -0
- package/zh/apis/app/hooks/api/functions/_category_.json +4 -0
- package/zh/apis/app/hooks/api/functions/api.md +50 -0
- package/zh/apis/app/hooks/api/functions/app.md +10 -0
- package/zh/apis/app/hooks/api/functions/common.md +10 -0
- package/zh/apis/app/hooks/api/test.md +12 -0
- package/zh/apis/app/hooks/config/_category_.json +4 -0
- package/zh/apis/app/hooks/config/html.md +10 -0
- package/zh/apis/app/hooks/config/icon.md +17 -0
- package/zh/apis/app/hooks/config/mock.md +12 -0
- package/zh/apis/app/hooks/config/public.md +30 -0
- package/zh/apis/app/hooks/config/storybook.md +14 -0
- package/zh/apis/app/hooks/config/upload.md +48 -0
- package/zh/apis/app/hooks/index.md +12 -0
- package/zh/apis/app/hooks/modern-config.md +10 -0
- package/zh/apis/app/hooks/server/_category_.json +4 -0
- package/zh/apis/app/hooks/server/index.md +14 -0
- package/zh/apis/app/hooks/server/test.md +12 -0
- package/zh/apis/app/hooks/shared.md +8 -0
- package/zh/apis/app/hooks/src/_category_.json +4 -0
- package/zh/apis/app/hooks/src/app.md +41 -0
- package/zh/apis/app/hooks/src/error.md +10 -0
- package/zh/apis/app/hooks/src/eslint.md +9 -0
- package/zh/apis/app/hooks/src/index.md +35 -0
- package/zh/apis/app/hooks/src/pages.md +183 -0
- package/zh/apis/app/hooks/src/stories.md +14 -0
- package/zh/apis/app/hooks/src/test.md +12 -0
- package/zh/apis/app/overview.md +11 -0
- package/zh/apis/app/runtime/_category_.json +9 -0
- package/zh/apis/app/runtime/app/_category_.json +4 -0
- package/zh/apis/app/runtime/app/bootstrap.md +83 -0
- package/zh/apis/app/runtime/app/create-app.md +47 -0
- package/zh/apis/app/runtime/app/define-config.md +57 -0
- package/zh/apis/app/runtime/app/head.md +43 -0
- package/zh/apis/app/runtime/app/no-ssr.md +41 -0
- package/zh/apis/app/runtime/app/pre-render.md +77 -0
- package/zh/apis/app/runtime/app/use-module-app.md +60 -0
- package/zh/apis/app/runtime/app/use-module-apps.md +64 -0
- package/zh/apis/app/runtime/app/use-runtime-context.md +39 -0
- package/zh/apis/app/runtime/bff-server/_category_.json +4 -0
- package/zh/apis/app/runtime/bff-server/after-lambda-registed.md +35 -0
- package/zh/apis/app/runtime/bff-server/hook.md +120 -0
- package/zh/apis/app/runtime/bff-server/use-context.md +70 -0
- package/zh/apis/app/runtime/container/_category_.json +4 -0
- package/zh/apis/app/runtime/container/router.md +492 -0
- package/zh/apis/app/runtime/container/use-loader.md +64 -0
- package/zh/apis/app/runtime/default-alias.md +26 -0
- package/zh/apis/app/runtime/env.md +68 -0
- package/zh/apis/app/runtime/index.md +12 -0
- package/zh/apis/app/runtime/model/Provider.md +36 -0
- package/zh/apis/app/runtime/model/_category_.json +4 -0
- package/zh/apis/app/runtime/model/auto-actions.md +121 -0
- package/zh/apis/app/runtime/model/connect.md +134 -0
- package/zh/apis/app/runtime/model/create-app.md +74 -0
- package/zh/apis/app/runtime/model/create-store.md +60 -0
- package/zh/apis/app/runtime/model/handle-effect.md +106 -0
- package/zh/apis/app/runtime/model/model_.md +199 -0
- package/zh/apis/app/runtime/model/use-local-model.md +28 -0
- package/zh/apis/app/runtime/model/use-model.md +87 -0
- package/zh/apis/app/runtime/model/use-static-model.md +47 -0
- package/zh/apis/app/runtime/model/use-store.md +48 -0
- package/zh/apis/app/runtime/plugin/_category_.json +4 -0
- package/zh/apis/app/runtime/plugin/abstract.md +26 -0
- package/zh/apis/app/runtime/plugin/hook-api.md +896 -0
- package/zh/apis/app/runtime/plugin/hook.md +170 -0
- package/zh/apis/app/runtime/plugin/plugin-api.md +117 -0
- package/zh/apis/app/runtime/testing/_category_.json +4 -0
- package/zh/apis/app/runtime/testing/act.md +34 -0
- package/zh/apis/app/runtime/testing/cleanup.md +37 -0
- package/zh/apis/app/runtime/testing/render.md +52 -0
- package/zh/apis/app/runtime/testing/renderApp.md +31 -0
- package/zh/apis/app/runtime/utility/_category_.json +4 -0
- package/zh/apis/app/runtime/utility/css-in-js.md +60 -0
- package/zh/apis/app/runtime/utility/loadable/_category_.json +4 -0
- package/zh/apis/app/runtime/utility/loadable/lazy.md +29 -0
- package/zh/apis/app/runtime/utility/loadable/loadable-component.md +61 -0
- package/zh/apis/app/runtime/utility/loadable/loadable-library.md +67 -0
- package/zh/apis/app/runtime/utility/loadable/loadable_.md +110 -0
- package/zh/apis/app/runtime/web-server/_category_.json +4 -0
- package/zh/apis/app/runtime/web-server/hook.md +121 -0
- package/zh/apis/generator/overview.md +32 -0
- package/zh/apis/generator/plugin/_category_.json +4 -0
- package/zh/apis/generator/plugin/file/_category_.json +4 -0
- package/zh/apis/generator/plugin/file/addFile.md +52 -0
- package/zh/apis/generator/plugin/file/addHelper.md +26 -0
- package/zh/apis/generator/plugin/file/addManyFile.md +55 -0
- package/zh/apis/generator/plugin/file/addPartial.md +26 -0
- package/zh/apis/generator/plugin/file/introduce.md +37 -0
- package/zh/apis/generator/plugin/file/rmDir.md +24 -0
- package/zh/apis/generator/plugin/file/rmFile.md +24 -0
- package/zh/apis/generator/plugin/file/updateJSONFile.md +52 -0
- package/zh/apis/generator/plugin/file/updateModernConfig.md +26 -0
- package/zh/apis/generator/plugin/file/updateTextRawFile.md +33 -0
- package/zh/apis/generator/plugin/git/_category_.json +4 -0
- package/zh/apis/generator/plugin/git/gitAddAndCommit.md +20 -0
- package/zh/apis/generator/plugin/git/initGitRepo.md +16 -0
- package/zh/apis/generator/plugin/git/isInGitRepo.md +16 -0
- package/zh/apis/generator/plugin/hook/_category_.json +4 -0
- package/zh/apis/generator/plugin/hook/afterForged.md +35 -0
- package/zh/apis/generator/plugin/hook/onForged.md +35 -0
- package/zh/apis/generator/plugin/info/_category_.json +4 -0
- package/zh/apis/generator/plugin/info/isFileExit.md +22 -0
- package/zh/apis/generator/plugin/info/locale.md +17 -0
- package/zh/apis/generator/plugin/info/readDir.md +22 -0
- package/zh/apis/generator/plugin/input/_category_.json +4 -0
- package/zh/apis/generator/plugin/input/addInputAfter.md +48 -0
- package/zh/apis/generator/plugin/input/addInputBefore.md +48 -0
- package/zh/apis/generator/plugin/input/addOptionAfter.md +45 -0
- package/zh/apis/generator/plugin/input/addOptionBefore.md +45 -0
- package/zh/apis/generator/plugin/input/setInput.md +42 -0
- package/zh/apis/generator/plugin/input/setInputValue.md +28 -0
- package/zh/apis/generator/plugin/input/type.md +101 -0
- package/zh/apis/generator/plugin/introduce.md +93 -0
- package/zh/apis/generator/plugin/new/_category_.json +4 -0
- package/zh/apis/generator/plugin/new/createElement.md +33 -0
- package/zh/apis/generator/plugin/new/createSubProject.md +35 -0
- package/zh/apis/generator/plugin/new/enableFunc.md +46 -0
- package/zh/apis/generator/plugin/new/introduce.md +15 -0
- package/zh/apis/generator/plugin/npm/_category_.json +4 -0
- package/zh/apis/generator/plugin/npm/install.md +16 -0
- package/zh/apis/monorepo/commands/_category_.json +8 -0
- package/zh/apis/monorepo/commands/bump.md +42 -0
- package/zh/apis/monorepo/commands/change.md +58 -0
- package/zh/apis/monorepo/commands/clear.md +27 -0
- package/zh/apis/monorepo/commands/deploy.md +39 -0
- package/zh/apis/monorepo/commands/gen-release-note.md +35 -0
- package/zh/apis/monorepo/commands/index.md +12 -0
- package/zh/apis/monorepo/commands/lint.md +21 -0
- package/zh/apis/monorepo/commands/new.md +41 -0
- package/zh/apis/monorepo/commands/pre.md +68 -0
- package/zh/apis/monorepo/commands/release.md +20 -0
- package/zh/apis/monorepo/commands/upgrade.md +23 -0
- package/zh/apis/monorepo/hooks/_category_.json +8 -0
- package/zh/apis/monorepo/hooks/apps.md +12 -0
- package/zh/apis/monorepo/hooks/code-workspace.md +10 -0
- package/zh/apis/monorepo/hooks/examples.md +14 -0
- package/zh/apis/monorepo/hooks/features.md +14 -0
- package/zh/apis/monorepo/hooks/index.md +12 -0
- package/zh/apis/monorepo/hooks/packages.md +14 -0
- package/zh/apis/monorepo/hooks/pnpm-workspace.md +10 -0
- package/zh/apis/monorepo/hooks/pnpmfile.md +10 -0
- package/zh/apis/monorepo/overview.md +11 -0
- package/zh/community/index.md +3 -0
- package/zh/components/command-tip.md +57 -0
- package/zh/components/deploy.md +60 -0
- package/zh/components/dev-ide.md +1 -0
- package/zh/components/entry-name.md +15 -0
- package/zh/components/env-prepare.md +1 -0
- package/zh/components/launch-bff-choices.md +6 -0
- package/zh/components/reduck-tip.md +5 -0
- package/zh/configure/app/bff/_category_.json +4 -0
- package/zh/configure/app/bff/fetcher.md +32 -0
- package/zh/configure/app/bff/prefix.md +38 -0
- package/zh/configure/app/bff/proxy.md +76 -0
- package/zh/configure/app/dev/_category_.json +4 -0
- package/zh/configure/app/dev/asset-prefix.md +13 -0
- package/zh/configure/app/dev/hmr.md +13 -0
- package/zh/configure/app/dev/https.md +13 -0
- package/zh/configure/app/dev/port.md +13 -0
- package/zh/configure/app/dev/progress-bar.md +13 -0
- package/zh/configure/app/dev/proxy.md +79 -0
- package/zh/configure/app/dev/start-url.md +13 -0
- package/zh/configure/app/dev/with-master-app.md +35 -0
- package/zh/configure/app/html/app-icon.md +13 -0
- package/zh/configure/app/html/crossorigin.md +13 -0
- package/zh/configure/app/html/disable-html-folder.md +13 -0
- package/zh/configure/app/html/favicon-by-entries.md +13 -0
- package/zh/configure/app/html/favicon.md +13 -0
- package/zh/configure/app/html/inject-by-entries.md +13 -0
- package/zh/configure/app/html/inject.md +13 -0
- package/zh/configure/app/html/meta-by-entries.md +13 -0
- package/zh/configure/app/html/meta.md +13 -0
- package/zh/configure/app/html/mount-id.md +13 -0
- package/zh/configure/app/html/template-by-entries.md +13 -0
- package/zh/configure/app/html/template-parameters-by-entries.md +13 -0
- package/zh/configure/app/html/template-parameters.md +13 -0
- package/zh/configure/app/html/template.md +13 -0
- package/zh/configure/app/html/title-by-entries.md +13 -0
- package/zh/configure/app/html/title.md +13 -0
- package/zh/configure/app/output/_category_.json +4 -0
- package/zh/configure/app/output/asset-prefix.md +13 -0
- package/zh/configure/app/output/assets-retry.md +13 -0
- package/zh/configure/app/output/charset.md +13 -0
- package/zh/configure/app/output/clean-dist-path.md +13 -0
- package/zh/configure/app/output/convert-to-rem.md +13 -0
- package/zh/configure/app/output/copy.md +13 -0
- package/zh/configure/app/output/css-module-local-ident-name.md +13 -0
- package/zh/configure/app/output/data-uri-limit.md +13 -0
- package/zh/configure/app/output/disable-css-module-extension.md +13 -0
- package/zh/configure/app/output/disable-filename-hash.md +13 -0
- package/zh/configure/app/output/disable-inline-runtime-chunk.md +13 -0
- package/zh/configure/app/output/disable-minimize.md +13 -0
- package/zh/configure/app/output/disable-node-polyfill.md +24 -0
- package/zh/configure/app/output/disable-source-map.md +13 -0
- package/zh/configure/app/output/dist-path.md +13 -0
- package/zh/configure/app/output/enable-asset-fallback.md +13 -0
- package/zh/configure/app/output/enable-asset-manifest.md +13 -0
- package/zh/configure/app/output/enable-css-module-tsdeclaration.md +13 -0
- package/zh/configure/app/output/enable-inline-scripts.md +13 -0
- package/zh/configure/app/output/enable-inline-styles.md +13 -0
- package/zh/configure/app/output/enable-latest-decorators.md +13 -0
- package/zh/configure/app/output/enable-modern-mode.md +26 -0
- package/zh/configure/app/output/externals.md +13 -0
- package/zh/configure/app/output/filename.md +13 -0
- package/zh/configure/app/output/legal-comments.md +13 -0
- package/zh/configure/app/output/override-browserslist.md +13 -0
- package/zh/configure/app/output/polyfill.md +13 -0
- package/zh/configure/app/output/ssg.md +226 -0
- package/zh/configure/app/output/svg-default-export.md +13 -0
- package/zh/configure/app/performance/build-cache.md +13 -0
- package/zh/configure/app/performance/bundle-analyze.md +13 -0
- package/zh/configure/app/performance/chunk-split.md +13 -0
- package/zh/configure/app/performance/print-file-size.md +13 -0
- package/zh/configure/app/performance/profile.md +13 -0
- package/zh/configure/app/performance/remove-console.md +13 -0
- package/zh/configure/app/performance/remove-moment-locale.md +13 -0
- package/zh/configure/app/plugins.md +74 -0
- package/zh/configure/app/runtime/_category_.json +4 -0
- package/zh/configure/app/runtime/master-app.md +72 -0
- package/zh/configure/app/runtime/router.md +54 -0
- package/zh/configure/app/runtime/state.md +45 -0
- package/zh/configure/app/security/sri.md +13 -0
- package/zh/configure/app/server/_category_.json +4 -0
- package/zh/configure/app/server/base-url.md +36 -0
- package/zh/configure/app/server/port.md +21 -0
- package/zh/configure/app/server/public-routes.md +29 -0
- package/zh/configure/app/server/routes.md +92 -0
- package/zh/configure/app/server/ssr-by-entries.md +32 -0
- package/zh/configure/app/server/ssr.md +24 -0
- package/zh/configure/app/source/_category_.json +4 -0
- package/zh/configure/app/source/alias.md +13 -0
- package/zh/configure/app/source/compile-js-data-uri.md +13 -0
- package/zh/configure/app/source/config-dir.md +15 -0
- package/zh/configure/app/source/define.md +13 -0
- package/zh/configure/app/source/design-system.md +1156 -0
- package/zh/configure/app/source/disable-default-entries.md +23 -0
- package/zh/configure/app/source/enable-async-entry.md +53 -0
- package/zh/configure/app/source/entries-dir.md +42 -0
- package/zh/configure/app/source/entries.md +55 -0
- package/zh/configure/app/source/global-vars.md +13 -0
- package/zh/configure/app/source/include.md +13 -0
- package/zh/configure/app/source/module-scopes.md +13 -0
- package/zh/configure/app/source/pre-entry.md +13 -0
- package/zh/configure/app/source/resolve-extension-prefix.md +13 -0
- package/zh/configure/app/source/resolve-main-fields.md +13 -0
- package/zh/configure/app/testing/_category_.json +4 -0
- package/zh/configure/app/testing/transformer.md +17 -0
- package/zh/configure/app/tools/_category_.json +4 -0
- package/zh/configure/app/tools/autoprefixer.md +13 -0
- package/zh/configure/app/tools/babel.md +13 -0
- package/zh/configure/app/tools/css-extract.md +13 -0
- package/zh/configure/app/tools/css-loader.md +13 -0
- package/zh/configure/app/tools/dev-server.md +13 -0
- package/zh/configure/app/tools/esbuild.md +61 -0
- package/zh/configure/app/tools/html-plugin.md +13 -0
- package/zh/configure/app/tools/inspector.md +13 -0
- package/zh/configure/app/tools/jest.md +41 -0
- package/zh/configure/app/tools/less.md +13 -0
- package/zh/configure/app/tools/minify-css.md +13 -0
- package/zh/configure/app/tools/postcss.md +13 -0
- package/zh/configure/app/tools/pug.md +13 -0
- package/zh/configure/app/tools/sass.md +13 -0
- package/zh/configure/app/tools/style-loader.md +13 -0
- package/zh/configure/app/tools/styled-components.md +13 -0
- package/zh/configure/app/tools/tailwindcss.md +48 -0
- package/zh/configure/app/tools/terser.md +13 -0
- package/zh/configure/app/tools/ts-checker.md +13 -0
- package/zh/configure/app/tools/ts-loader.md +13 -0
- package/zh/configure/app/tools/webpack-chain.md +13 -0
- package/zh/configure/app/tools/webpack.md +13 -0
- package/zh/configure/app/usage.md +81 -0
- package/zh/configure/generator/introduce.md +113 -0
- package/zh/configure/generator/module.md +43 -0
- package/zh/configure/generator/monorepo.md +28 -0
- package/zh/configure/generator/mwa.md +127 -0
- package/zh/guides/advanced-features/_category_.json +9 -0
- package/zh/guides/advanced-features/bff/_category_.json +4 -0
- package/zh/guides/advanced-features/bff/bff-proxy.md +25 -0
- package/zh/guides/advanced-features/bff/bff-server.md +142 -0
- package/zh/guides/advanced-features/bff/frameworks.md +348 -0
- package/zh/guides/advanced-features/bff/function.md +236 -0
- package/zh/guides/advanced-features/code-split.md +68 -0
- package/zh/guides/advanced-features/compatibility.md +89 -0
- package/zh/guides/advanced-features/custom-app.md +4 -0
- package/zh/guides/advanced-features/eslint.md +146 -0
- package/zh/guides/advanced-features/index.md +12 -0
- package/zh/guides/advanced-features/low-level.md +44 -0
- package/zh/guides/advanced-features/ssg.md +151 -0
- package/zh/guides/advanced-features/ssr.md +186 -0
- package/zh/guides/advanced-features/testing.md +4 -0
- package/zh/guides/advanced-features/typescript.md +4 -0
- package/zh/guides/advanced-features/web-server.md +135 -0
- package/zh/guides/basic-features/_category_.json +9 -0
- package/zh/guides/basic-features/alias.md +67 -0
- package/zh/guides/basic-features/css/_category_.json +4 -0
- package/zh/guides/basic-features/css/css-in-js.md +38 -0
- package/zh/guides/basic-features/css/css-modules.md +86 -0
- package/zh/guides/basic-features/css/less-sass.md +29 -0
- package/zh/guides/basic-features/css/postcss.md +81 -0
- package/zh/guides/basic-features/css/tailwindcss.md +98 -0
- package/zh/guides/basic-features/data-fetch.md +4 -0
- package/zh/guides/basic-features/env-vars.md +83 -0
- package/zh/guides/basic-features/html.md +128 -0
- package/zh/guides/basic-features/image.md +43 -0
- package/zh/guides/basic-features/index.md +12 -0
- package/zh/guides/basic-features/mock.md +85 -0
- package/zh/guides/basic-features/proxy.md +85 -0
- package/zh/guides/basic-features/routes.md +4 -0
- package/zh/guides/concept/_category_.json +5 -0
- package/zh/guides/concept/entries.md +4 -0
- package/zh/guides/concept/integrated.md +4 -0
- package/zh/guides/concept/lifecycle.md +4 -0
- package/zh/guides/concept/solutions.md +4 -0
- package/zh/guides/get-started/_category_.json +5 -0
- package/zh/guides/get-started/quick-start.md +4 -0
- package/zh/guides/get-started/upgrade.md +4 -0
- package/zh/guides/overview.md +11 -0
- package/zh/guides/topic-detail/_category_.json +5 -0
- package/zh/guides/topic-detail/changesets/_category_.json +4 -0
- package/zh/guides/topic-detail/changesets/add.md +125 -0
- package/zh/guides/topic-detail/changesets/changelog.md +239 -0
- package/zh/guides/topic-detail/changesets/commit.md +272 -0
- package/zh/guides/topic-detail/changesets/config.md +146 -0
- package/zh/guides/topic-detail/changesets/github.md +168 -0
- package/zh/guides/topic-detail/changesets/introduce.md +57 -0
- package/zh/guides/topic-detail/changesets/release-note.md +262 -0
- package/zh/guides/topic-detail/changesets/release-pre.md +49 -0
- package/zh/guides/topic-detail/changesets/release.md +228 -0
- package/zh/guides/topic-detail/compile-speed.md +182 -0
- package/zh/guides/topic-detail/framework-plugin/_category_.json +4 -0
- package/zh/guides/topic-detail/framework-plugin/abstract.md +27 -0
- package/zh/guides/topic-detail/framework-plugin/extend.md +163 -0
- package/zh/guides/topic-detail/framework-plugin/implement.md +188 -0
- package/zh/guides/topic-detail/framework-plugin/relationship.md +119 -0
- package/zh/guides/topic-detail/generator-plugin/_category_.json +4 -0
- package/zh/guides/topic-detail/generator-plugin/abstract.md +23 -0
- package/zh/guides/topic-detail/generator-plugin/develop.md +120 -0
- package/zh/guides/topic-detail/generator-plugin/use.md +61 -0
- package/zh/guides/topic-detail/micro-frontend/_category_.json +4 -0
- package/zh/guides/topic-detail/micro-frontend/communicate.md +39 -0
- package/zh/guides/topic-detail/micro-frontend/debugging.md +168 -0
- package/zh/guides/topic-detail/micro-frontend/introduction.md +13 -0
- package/zh/guides/topic-detail/micro-frontend/mixed-stack.md +24 -0
- package/zh/guides/topic-detail/micro-frontend/route-mode.md +110 -0
- package/zh/guides/topic-detail/model/_category_.json +4 -0
- package/zh/guides/topic-detail/model/auto-actions.md +90 -0
- package/zh/guides/topic-detail/model/computed-state.md +151 -0
- package/zh/guides/topic-detail/model/define-model.md +66 -0
- package/zh/guides/topic-detail/model/faq.md +43 -0
- package/zh/guides/topic-detail/model/manage-effects.md +259 -0
- package/zh/guides/topic-detail/model/model-communicate.md +219 -0
- package/zh/guides/topic-detail/model/performance.md +173 -0
- package/zh/guides/topic-detail/model/quick-start.md +112 -0
- package/zh/guides/topic-detail/model/redux-integration.md +21 -0
- package/zh/guides/topic-detail/model/test-model.md +43 -0
- package/zh/guides/topic-detail/model/typescript-best-practice.md +71 -0
- package/zh/guides/topic-detail/model/use-model.md +244 -0
- package/zh/guides/topic-detail/model/use-out-of-modernjs.md +51 -0
- package/zh/guides/topic-detail/monorepo/_category_.json +4 -0
- package/zh/guides/topic-detail/monorepo/create-sub-project.md +64 -0
- package/zh/guides/topic-detail/monorepo/deploy.md +43 -0
- package/zh/guides/topic-detail/monorepo/intro.md +15 -0
- package/zh/guides/topic-detail/monorepo/publish.md +68 -0
- package/zh/guides/topic-detail/monorepo/sub-project-interface.md +170 -0
- package/zh/guides/troubleshooting/_category_.json +5 -0
- package/zh/guides/troubleshooting/compile.md +379 -0
- package/zh/guides/troubleshooting/dependencies.md +168 -0
- package/zh/tutorials/first-app/_category_.json +5 -0
- package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +25 -0
- package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +118 -0
- package/zh/tutorials/first-app/c01-getting-started/1.3-dev-command.md +29 -0
- package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +44 -0
- package/zh/tutorials/first-app/c01-getting-started/1.5-start-command.md +18 -0
- package/zh/tutorials/first-app/c01-getting-started/1.6-create-repo.md +31 -0
- package/zh/tutorials/first-app/c01-getting-started/_category_.json +3 -0
- package/zh/tutorials/first-app/c02-generator-and-studio/2.1-generator.md +87 -0
- package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +28 -0
- package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +21 -0
- package/zh/tutorials/first-app/c02-generator-and-studio/_category_.json +3 -0
- package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +55 -0
- package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +66 -0
- package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +11 -0
- package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +63 -0
- package/zh/tutorials/first-app/c03-ide/_category_.json +3 -0
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +67 -0
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +111 -0
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.3-compatibility.md +67 -0
- package/zh/tutorials/first-app/c04-es6-plus-and-ts/_category_.json +3 -0
- package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +68 -0
- package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +92 -0
- package/zh/tutorials/first-app/c05-component/_category_.json +3 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +110 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +148 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +84 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +83 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +77 -0
- package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +113 -0
- package/zh/tutorials/first-app/c06-css-and-component/_category_.json +3 -0
- package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +64 -0
- package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +104 -0
- package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +74 -0
- package/zh/tutorials/first-app/c07-app-entry/_category_.json +3 -0
- package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +153 -0
- package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +318 -0
- package/zh/tutorials/first-app/c08-client-side-routing/_category_.json +3 -0
- package/zh/tutorials/first-app/c09-bff/9.1-serverless.md +30 -0
- package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +93 -0
- package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +205 -0
- package/zh/tutorials/first-app/c09-bff/_category_.json +3 -0
- package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +23 -0
- package/zh/tutorials/first-app/c10-model/10.2-add-model.md +185 -0
- package/zh/tutorials/first-app/c10-model/10.3-use-model.md +54 -0
- package/zh/tutorials/first-app/c10-model/10.4-testing.md +69 -0
- package/zh/tutorials/first-app/c10-model/_category_.json +3 -0
- package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +274 -0
- package/zh/tutorials/first-app/c11-container/11.2-add-container.md +106 -0
- package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +61 -0
- package/zh/tutorials/first-app/c11-container/11.4-testing.md +56 -0
- package/zh/tutorials/first-app/c11-container/_category_.json +3 -0
- package/zh/tutorials/first-app/overview.md +11 -0
- package/zh/tutorials/foundations/_category_.json +5 -0
- package/zh/tutorials/foundations/basic.md +8 -0
- package/zh/tutorials/foundations/introduction.md +41 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
---
|
2
|
+
title: 用 Utility Class 写组件
|
3
|
+
---
|
4
|
+
|
5
|
+
上一小节我们学习了如何使用 style-components 实现 `Avatar` 组件。
|
6
|
+
|
7
|
+
但当前的 UI 仍然不能让人满意,缺乏专业感,例如列表项内部的布局有点粗糙,很多地方没对齐。
|
8
|
+
|
9
|
+
本小节中,我们自己来实现一个更好的 `Item` 组件,实现这样的设计稿:
|
10
|
+
|
11
|
+

|
12
|
+
|
13
|
+
这次要实现的 UI 更复杂,有内部结构,但另一方面,并没有 `Avatar` 组件的**很粗的亮蓝色边框**这样很特殊的 UI,都是很常规的水平垂直布局、居中、字体样式等。
|
14
|
+
|
15
|
+
这种情况下,其实根本没必要写 CSS,有更高效的、跟 styled-components 互补的实现方式:Utility Class。
|
16
|
+
|
17
|
+
Modern.js 集成了主流、轻量、通用的 Utility Class 工具库 [Tailwind CSS](https://tailwindcss.com/)。
|
18
|
+
|
19
|
+
执行 `pnpm run new`,进行如下选择,开启 Tailwind CSS:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
# 启用可选功能
|
23
|
+
❯ 启用 Tailwind CSS 支持
|
24
|
+
启用 Sass 支持
|
25
|
+
...
|
26
|
+
```
|
27
|
+
|
28
|
+
:::info 注
|
29
|
+
因为我们之前已经开启了 Less 支持,所以再次添加可选功能时,不再有这个选项。
|
30
|
+
:::
|
31
|
+
|
32
|
+
在 `src/App.tsx` 顶部引入 Tailwind CSS 的 css 文件,就可以开始快速实现专业的 UI:
|
33
|
+
|
34
|
+
```js
|
35
|
+
import 'tailwindcss/base.css';
|
36
|
+
import 'tailwindcss/components.css';
|
37
|
+
import 'tailwindcss/utilities.css';
|
38
|
+
```
|
39
|
+
|
40
|
+
先创建 Item 组件:
|
41
|
+
|
42
|
+
import Tabs from '@theme/Tabs';
|
43
|
+
import TabItem from '@theme/TabItem';
|
44
|
+
|
45
|
+
<Tabs>
|
46
|
+
<TabItem value="macOS" label="macOS" default>
|
47
|
+
|
48
|
+
```bash
|
49
|
+
mkdir -p src/components/Item
|
50
|
+
touch src/components/Item/index.tsx
|
51
|
+
```
|
52
|
+
|
53
|
+
</TabItem>
|
54
|
+
<TabItem value="Windows" label="Windows">
|
55
|
+
|
56
|
+
```powershell
|
57
|
+
mkdir -p src/components/Item
|
58
|
+
ni src/components/Item/index.tsx
|
59
|
+
```
|
60
|
+
|
61
|
+
</TabItem>
|
62
|
+
</Tabs>
|
63
|
+
|
64
|
+
修改 `src/App.tsx`,把 `List` 的 `render` 实现交给 `Item` 组件:
|
65
|
+
|
66
|
+
```js
|
67
|
+
import { List } from 'antd';
|
68
|
+
import 'tailwindcss/base.css';
|
69
|
+
import 'tailwindcss/components.css';
|
70
|
+
import 'tailwindcss/utilities.css';
|
71
|
+
import Item from './components/Item';
|
72
|
+
|
73
|
+
const getAvatar = (users: Array<{ name: string; email: string }>) =>
|
74
|
+
users.map(user => ({
|
75
|
+
...user,
|
76
|
+
avatar: `https://avatars.dicebear.com/v2/identicon/${user.name}.svg`,
|
77
|
+
}));
|
78
|
+
|
79
|
+
const mockData = getAvatar([
|
80
|
+
{ name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
|
81
|
+
{ name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
|
82
|
+
{ name: 'Bradley', email: 'd.wfovsqyo@gpkcjwjgb.fr' },
|
83
|
+
{ name: 'Davis', email: '"t.kqkoj@utlkwnpwk.nu' },
|
84
|
+
]);
|
85
|
+
|
86
|
+
function App() {
|
87
|
+
return (
|
88
|
+
<div className="container lg mx-auto">
|
89
|
+
<List
|
90
|
+
dataSource={mockData}
|
91
|
+
renderItem={info => <Item key={info.name} info={info} />}
|
92
|
+
/>
|
93
|
+
</div>
|
94
|
+
);
|
95
|
+
}
|
96
|
+
|
97
|
+
export default App;
|
98
|
+
```
|
99
|
+
|
100
|
+
在父容器的上使用了 [Utility Class](https://tailwindcss.com/docs/container) ,快速实现了最基本的 [RWD](https://tailwindcss.com/docs/responsive-design)(最大宽度、居中)。
|
101
|
+
|
102
|
+
接下来实现 `src/components/Item/index.tsx`:
|
103
|
+
|
104
|
+
```tsx
|
105
|
+
import Avatar from '../Avatar';
|
106
|
+
|
107
|
+
type InfoProps = {
|
108
|
+
avatar: string;
|
109
|
+
name: string;
|
110
|
+
email: string;
|
111
|
+
archived?: boolean;
|
112
|
+
};
|
113
|
+
|
114
|
+
const Item = ({ info }: { info: InfoProps }) => {
|
115
|
+
const { avatar, name, email, archived } = info;
|
116
|
+
return (
|
117
|
+
<div className="flex p-4 items-center border-gray-200 border-b">
|
118
|
+
<Avatar src={avatar} />
|
119
|
+
<div className="ml-4 flex-1 flex justify-between">
|
120
|
+
<div className="flex-1">
|
121
|
+
<p>{name}</p>
|
122
|
+
<p>{email}</p>
|
123
|
+
</div>
|
124
|
+
<button
|
125
|
+
type="button"
|
126
|
+
disabled={archived}
|
127
|
+
className={`bg-blue-500 text-white font-bold
|
128
|
+
py-2 px-4 rounded-full hover:bg-blue-700`}>
|
129
|
+
Archive
|
130
|
+
</button>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
);
|
134
|
+
};
|
135
|
+
|
136
|
+
export default Item;
|
137
|
+
```
|
138
|
+
|
139
|
+
执行 `pnpm run dev`,可以看到预期的运行结果:
|
140
|
+
|
141
|
+

|
142
|
+
|
143
|
+
这一小节中,我们只使用了少量 Utility Class,比如 [Flex](https://tailwindcss.com/docs/display/)、[Padding](https://tailwindcss.com/docs/padding/)、[Margin](https://tailwindcss.com/docs/margin/)、[Text](https://tailwindcss.com/docs/text-color/)、[Font](https://tailwindcss.com/docs/font-weight/)、[Border](https://tailwindcss.com/docs/border-width),不写一行 CSS 就实现了有【 设计系统(Design System)】的、符合设计稿的专业 UI。
|
144
|
+
|
145
|
+
---
|
146
|
+
|
147
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c06/hello-modern-2)。
|
148
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
---
|
2
|
+
title: 添加新的 Utility Class
|
3
|
+
---
|
4
|
+
|
5
|
+
上一小节,我们学习了如何使用通用的 Utility Class 工具库.
|
6
|
+
|
7
|
+
我们不但可以自己写组件,也可以自己实现新的 Utility Class,方便在代码间复用。
|
8
|
+
|
9
|
+
Utility Class 本身也是一种**面向组件**的技术(将不同 class 用在一个组件上,等价于给这个组件设置了一些来自基类的属性),但 Utility Class 的 classname 是全局的(因为要用在任意组件/元素上),很适合用独立 CSS 文件来实现。
|
10
|
+
|
11
|
+
创建一个新的 CSS 文件:
|
12
|
+
|
13
|
+
import Tabs from '@theme/Tabs';
|
14
|
+
import TabItem from '@theme/TabItem';
|
15
|
+
|
16
|
+
<Tabs>
|
17
|
+
<TabItem value="macOS" label="macOS" default>
|
18
|
+
|
19
|
+
```bash
|
20
|
+
mkdir -p src/styles
|
21
|
+
touch src/styles/utils.css
|
22
|
+
```
|
23
|
+
|
24
|
+
</TabItem>
|
25
|
+
<TabItem value="Windows" label="Windows">
|
26
|
+
|
27
|
+
```powershell
|
28
|
+
mkdir -p src/styles
|
29
|
+
ni src/styles/utils.css
|
30
|
+
```
|
31
|
+
|
32
|
+
</TabItem>
|
33
|
+
</Tabs>
|
34
|
+
|
35
|
+
在 `src/App.tsx` 里导入 `utils.css`:
|
36
|
+
|
37
|
+
```js
|
38
|
+
import './styles/utils.css';
|
39
|
+
```
|
40
|
+
|
41
|
+
在 `src/styles/utils.css` 里实现一个叫作 `custom-text-gray` 的 Utility Class。
|
42
|
+
|
43
|
+
```css
|
44
|
+
:root {
|
45
|
+
--custom-text-color:rgb(113, 128, 150);
|
46
|
+
}
|
47
|
+
|
48
|
+
.custom-text-gray {
|
49
|
+
color: var(--custom-text-color);
|
50
|
+
}
|
51
|
+
```
|
52
|
+
|
53
|
+
:::info 注
|
54
|
+
Modern.js 集成了 [PostCSS](/docs/guides/basic-features/css/postcss),支持现代 CSS 语法特性,比如 [custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/--*)。
|
55
|
+
:::
|
56
|
+
|
57
|
+
在 `src/components/Item/index.tsx` 里使用,把:
|
58
|
+
|
59
|
+
```js
|
60
|
+
<div className="ml-4 flex-1 flex justify-between">
|
61
|
+
```
|
62
|
+
|
63
|
+
改成:
|
64
|
+
|
65
|
+
```js
|
66
|
+
<div className="ml-4 custom-text-gray flex-1 flex justify-between">
|
67
|
+
```
|
68
|
+
|
69
|
+
执行 `pnpm run dev`,可以看到字体颜色改变了:
|
70
|
+
|
71
|
+

|
72
|
+
|
73
|
+
:::info 注
|
74
|
+
此处只是为了演示 Utility Class 用法。真实项目中,在有 Tailwind CSS 的情况下,这种 Utility Class 没什么价值,应该通过配置 Design System 的 [**theme**](https://tailwindcss.com/docs/customizing-colors) 来增加字体颜色。
|
75
|
+
|
76
|
+
`utils.css` 也可以写成 `utils.scss` 或 `utils.less`,Modern.js 对 SCSS 和 Less 同样提供开箱即用的支持。
|
77
|
+
|
78
|
+
不过在 PostCSS 的支持下,现代 CSS 应该足以满足这些开发需求,性能相较于预处理器也更好,建议优先用 .css 文件。
|
79
|
+
:::
|
80
|
+
|
81
|
+
---
|
82
|
+
|
83
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c06/hello-modern-3)。
|
84
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
---
|
2
|
+
title: 管理 Design System
|
3
|
+
---
|
4
|
+
|
5
|
+
在前两个小节中,我们了解了 Utility Class 以及使用了 Modern.js 已经集成的 Utility Class 工具库 [Tailwind CSS](https://tailwindcss.com/),
|
6
|
+
默认提供的设计系统生成的样式可以满足实际开发中的部分需求。
|
7
|
+
|
8
|
+
然而实际开发中,我们可能需要修改默认的设计系统规范。为此,Modern.js 提供了
|
9
|
+
[`source.designSystem`](/docs/configure/app/source/design-system) 配置来管理项目的设计系统。
|
10
|
+
|
11
|
+
## 覆盖默认配置
|
12
|
+
|
13
|
+
要覆盖默认的设计系统配置,请在 `modern.config.js` 的 `source.designSystem` 中添加要覆盖的键。
|
14
|
+
|
15
|
+
```js title="modern.config.js"
|
16
|
+
export default defineConfig({
|
17
|
+
source: {
|
18
|
+
designSystem: {
|
19
|
+
opacity: {
|
20
|
+
0: '0',
|
21
|
+
20: '0.2',
|
22
|
+
40: '0.4',
|
23
|
+
60: '0.6',
|
24
|
+
80: '0.8',
|
25
|
+
100: '1',
|
26
|
+
},
|
27
|
+
},
|
28
|
+
},
|
29
|
+
});
|
30
|
+
```
|
31
|
+
|
32
|
+
这将完全替换默认键配置,因此在上面的示例中,不会生成默认的 opacity utilities。
|
33
|
+
|
34
|
+
所有未覆盖的键都将从默认主题继承,因此在上面的示例中,将保留颜色,间距,边框圆角,背景位置等内容的默认主题配置。
|
35
|
+
|
36
|
+
## 扩展默认配置
|
37
|
+
|
38
|
+
如果您想保留主题选项的默认值,但又要添加新值,请在 `designSystem.extend` 下添加扩展的内容。
|
39
|
+
|
40
|
+
例如,如果我们想添加一个额外的断点但保留现有的断点,则可以扩展 `screens` 属性:
|
41
|
+
|
42
|
+
```js title="modern.config.js"
|
43
|
+
export default defineConfig({
|
44
|
+
source: {
|
45
|
+
designSystem: {
|
46
|
+
opacity: {
|
47
|
+
0: '0',
|
48
|
+
20: '0.2',
|
49
|
+
40: '0.4',
|
50
|
+
60: '0.6',
|
51
|
+
80: '0.8',
|
52
|
+
100: '1',
|
53
|
+
},
|
54
|
+
extend: {
|
55
|
+
screens: {
|
56
|
+
'2xl': '1440px',
|
57
|
+
},
|
58
|
+
},
|
59
|
+
},
|
60
|
+
},
|
61
|
+
});
|
62
|
+
```
|
63
|
+
|
64
|
+
修改 `src/Item/index.tsx` 的 button 组件代码
|
65
|
+
|
66
|
+
```js
|
67
|
+
<button
|
68
|
+
type="button"
|
69
|
+
disabled={archived}
|
70
|
+
className={`bg-blue-500 text-white font-bold
|
71
|
+
py-2 px-4 rounded-full hover:bg-blue-700 2xl:bg-red-500`}
|
72
|
+
>
|
73
|
+
Archive
|
74
|
+
</button>
|
75
|
+
```
|
76
|
+
|
77
|
+
执行 `pnpm run dev` 后,增加页面宽度超过 1440px 可以看到 button 颜色变化:
|
78
|
+
|
79
|
+

|
80
|
+
|
81
|
+
---
|
82
|
+
|
83
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c06/hello-modern-4)。
|
@@ -0,0 +1,77 @@
|
|
1
|
+
---
|
2
|
+
title: 用 Storybook 调试组件
|
3
|
+
---
|
4
|
+
|
5
|
+
前几个小节中,我们已经开发了一个简单的 UI 组件。组件开发完后,一般我们需要对它进行调试。
|
6
|
+
|
7
|
+
除了可以直接在项目中进行调试以外,我们还可以使用 [**Storybook**](https://storybook.js.org/) 进行调试。
|
8
|
+
|
9
|
+
Modern.js 提供了开箱即用的 Storybook 能力,可以识别应用工程下的 Story 文件。
|
10
|
+
|
11
|
+
我们执行 `pnpm run new`,启用该模式:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
# 启用可选功能
|
15
|
+
...
|
16
|
+
启用「单元测试 / 集成测试」功能
|
17
|
+
❯ 启用「Visual Testing (Storybook)」模式
|
18
|
+
```
|
19
|
+
|
20
|
+
安装成功后,我们需要为我们的组件添加 Story 文件。
|
21
|
+
|
22
|
+
:::info 补充信息
|
23
|
+
Story 文件是指 `*.stories.[t|j]sx?` 格式的文件。
|
24
|
+
:::
|
25
|
+
|
26
|
+
这里我们为 `Avatar` 组件 添加 `src/components/Avatar/index.stories.tsx` Story 文件。
|
27
|
+
|
28
|
+
import Tabs from '@theme/Tabs';
|
29
|
+
import TabItem from '@theme/TabItem';
|
30
|
+
|
31
|
+
<Tabs>
|
32
|
+
<TabItem value="macOS" label="macOS" default>
|
33
|
+
|
34
|
+
```bash
|
35
|
+
touch src/components/Avatar/index.stories.tsx
|
36
|
+
```
|
37
|
+
|
38
|
+
</TabItem>
|
39
|
+
<TabItem value="Windows" label="Windows">
|
40
|
+
|
41
|
+
```powershell
|
42
|
+
ni src/components/Avatar/index.stories.tsx
|
43
|
+
```
|
44
|
+
|
45
|
+
</TabItem>
|
46
|
+
</Tabs>
|
47
|
+
|
48
|
+
内容如下:
|
49
|
+
|
50
|
+
``` javascript
|
51
|
+
import Avatar from '.';
|
52
|
+
|
53
|
+
export const DanielTaylorAvatar = () => (
|
54
|
+
<Avatar src="https://avatars.dicebear.com/v2/identicon/Daniel Taylor.svg" />
|
55
|
+
);
|
56
|
+
|
57
|
+
export default {
|
58
|
+
title: 'Avatar Demo',
|
59
|
+
};
|
60
|
+
```
|
61
|
+
|
62
|
+
然后我们启动 Storybook 调试:
|
63
|
+
|
64
|
+
``` bash
|
65
|
+
pnpm run dev story
|
66
|
+
```
|
67
|
+
|
68
|
+
然后我们可以看到如下界面:
|
69
|
+
|
70
|
+

|
71
|
+
|
72
|
+
如果需要配置 Storybook,则需要在 [`config/storybook/**`](/docs/apis/app/hooks/config/storybook) 目录下进行配置。
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c06/hello-modern-5)。
|
77
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
---
|
2
|
+
title: 测试组件
|
3
|
+
---
|
4
|
+
|
5
|
+
Modern.js 集成了 [Jest](https://jestjs.io/),不需要做任何配置,可以直接给组件写测试用例。
|
6
|
+
|
7
|
+
我们执行 `pnpm run new` 开启测试功能:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
# 启用可选功能
|
11
|
+
❯ 启用「单元测试 / 集成测试」功能
|
12
|
+
```
|
13
|
+
|
14
|
+
可以用以下两种方式给 Item 组件创建测试用例:
|
15
|
+
|
16
|
+
import Tabs from '@theme/Tabs';
|
17
|
+
import TabItem from '@theme/TabItem';
|
18
|
+
|
19
|
+
<Tabs>
|
20
|
+
<TabItem value="macOS" label="macOS" default>
|
21
|
+
|
22
|
+
```bash
|
23
|
+
touch src/components/Item/index.test.tsx
|
24
|
+
```
|
25
|
+
|
26
|
+
</TabItem>
|
27
|
+
<TabItem value="Windows" label="Windows">
|
28
|
+
|
29
|
+
```powershell
|
30
|
+
ni src/components/Item/index.test.tsx
|
31
|
+
```
|
32
|
+
|
33
|
+
</TabItem>
|
34
|
+
</Tabs>
|
35
|
+
|
36
|
+
或
|
37
|
+
|
38
|
+
<Tabs>
|
39
|
+
<TabItem value="macOS" label="macOS" default>
|
40
|
+
|
41
|
+
```bash
|
42
|
+
mkdir -p src/components/Item/__tests__/
|
43
|
+
touch src/components/Item/__tests__/index.tsx
|
44
|
+
```
|
45
|
+
|
46
|
+
</TabItem>
|
47
|
+
<TabItem value="Windows" label="Windows">
|
48
|
+
|
49
|
+
```powershell
|
50
|
+
mkdir -p src/components/Item/__tests__/
|
51
|
+
ni src/components/Item/__tests__/index.tsx
|
52
|
+
```
|
53
|
+
|
54
|
+
</TabItem>
|
55
|
+
</Tabs>
|
56
|
+
|
57
|
+
|
58
|
+
以前者为例,`Item/index.test.tsx` 的内容:
|
59
|
+
|
60
|
+
```js
|
61
|
+
import { render } from '@modern-js/runtime/testing';
|
62
|
+
import Item from '.';
|
63
|
+
|
64
|
+
const defaultProps = {
|
65
|
+
info: {
|
66
|
+
avatar: 'https://via.placeholder.com/350x350',
|
67
|
+
name: 'foo',
|
68
|
+
email: 'foo.bar@bytedance.com',
|
69
|
+
archived: false,
|
70
|
+
},
|
71
|
+
};
|
72
|
+
|
73
|
+
describe('Item', () => {
|
74
|
+
it('should have contents', () => {
|
75
|
+
const {
|
76
|
+
info: { name },
|
77
|
+
} = defaultProps;
|
78
|
+
const { getByText } = render(<Item {...defaultProps} />);
|
79
|
+
expect(getByText(name)).toBeInTheDocument();
|
80
|
+
});
|
81
|
+
});
|
82
|
+
```
|
83
|
+
|
84
|
+
在之前章节创建的 `modern-app-env.d.ts` 文件 **顶部**([`///` 语法只在文件顶部生效](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#:~:text=Triple-slash%20directives%20are%20only%20valid%20at%20the%20top%20of%20their%20containing%20file.)) 加上类型定义:
|
85
|
+
|
86
|
+
```ts
|
87
|
+
/// <reference types="@modern-js/plugin-testing/type" />
|
88
|
+
```
|
89
|
+
|
90
|
+
:::info 注
|
91
|
+
更多相关内容可以查看 [Test API](/docs/apis/app/runtime/testing/render)。
|
92
|
+
:::
|
93
|
+
|
94
|
+
执行 `pnpm run test`,可以看到测试报告:
|
95
|
+
|
96
|
+
```bash
|
97
|
+
> modern test
|
98
|
+
|
99
|
+
PASS src/components/Item/index.test.tsx
|
100
|
+
Item
|
101
|
+
✓ should have contents (27 ms)
|
102
|
+
|
103
|
+
Test Suites: 1 passed, 1 total
|
104
|
+
Tests: 1 passed, 1 total
|
105
|
+
Snapshots: 0 total
|
106
|
+
Time: 1.048 s, estimated 2 s
|
107
|
+
Ran all test suites.
|
108
|
+
```
|
109
|
+
|
110
|
+
---
|
111
|
+
|
112
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c06/hello-modern-6)。
|
113
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
title: 入口的用途
|
3
|
+
---
|
4
|
+
|
5
|
+
上一章节中,我们介绍了如何编写 UI 组件。
|
6
|
+
|
7
|
+
这一章节中,继续沿用之前的代码,到目前为止,hello-modern 的目录结构是这样的:
|
8
|
+
|
9
|
+
```md
|
10
|
+
.
|
11
|
+
├── .vscode/
|
12
|
+
├── src/
|
13
|
+
│ ├── components/
|
14
|
+
│ │ ├── Avatar/
|
15
|
+
│ │ │ ├── index.stories.tsx
|
16
|
+
│ │ │ └── index.tsx
|
17
|
+
│ │ └── Item/
|
18
|
+
│ │ ├── index.test.tsx
|
19
|
+
│ │ └── index.tsx
|
20
|
+
│ ├── styles/
|
21
|
+
│ │ └── utils.css
|
22
|
+
│ ├── .eslintrc.json
|
23
|
+
│ ├── App.css
|
24
|
+
│ ├── App.tsx
|
25
|
+
│ └── modern-app-env.d.ts
|
26
|
+
├── .editorconfig
|
27
|
+
├── .gitignore
|
28
|
+
├── .npmrc
|
29
|
+
├── .nvmrc
|
30
|
+
├── README.md
|
31
|
+
├── package.json
|
32
|
+
├── pnpm-lock.yaml
|
33
|
+
└── tsconfig.json
|
34
|
+
```
|
35
|
+
|
36
|
+
hello-modern 项目是一个应用工程,`src/` 目录里是应用工程源代码的主要部分,我们称之为【 Universal App 代码(大一统应用代码)】—— 既可以在客户端运行又可以在服务器端运行,有多种运行模式和部署模式,既能实现多页(MPA)也能实现单页(SPA)。
|
37
|
+
|
38
|
+
我们把 `src/App.tsx` 称作【 应用入口(App Entry)】,一个应用工程可以有一到多个应用入口。
|
39
|
+
|
40
|
+
:::info 注
|
41
|
+
应用入口不止 `App.[jt]sx` 一种,之后章节中会再次介绍。
|
42
|
+
:::
|
43
|
+
|
44
|
+
:::info 注
|
45
|
+
在不启用 SSG(Static Site Generation)的情况下,Modern.js 会为每一个应用入口,都自动生成一个对应的 HTML,用于在浏览器、WebView 等平台上运行。
|
46
|
+
|
47
|
+
一个应用入口适用于:
|
48
|
+
|
49
|
+
- 一个中后台应用(SPA)
|
50
|
+
- 一个桌面应用(SPA、Electron App)
|
51
|
+
- 一个PWA
|
52
|
+
- 一个大型的多页网站(SPA + SSR)
|
53
|
+
- 一个落地页、活动页或分享页
|
54
|
+
- 一个端内界面
|
55
|
+
- 一个微前端子应用
|
56
|
+
- ……
|
57
|
+
|
58
|
+
多个应用入口适用于:
|
59
|
+
|
60
|
+
- 简单的多页网站(多个 HTML 互相链接)
|
61
|
+
- 由多种不同类型入口组成的产品『系统』(整个产品不是单一的客户端,而是由多种不同客户端组成,比如同时有落地页、端内界面、端外独立 Web App、后台管理应用)
|
62
|
+
:::
|
63
|
+
|
64
|
+
hello-modern 项目目前是【 单入口 】形式的,我们接下来添加一个新入口,实现这个联系人列表应用的落地页,把项目转变成【 多入口 】形式。
|
@@ -0,0 +1,104 @@
|
|
1
|
+
---
|
2
|
+
title: 用 new 命令创建入口
|
3
|
+
---
|
4
|
+
|
5
|
+
Modern.js 支持自动创建新入口,前面的章节中提到过,`pnpm run new` 可以启用可选功能。
|
6
|
+
|
7
|
+
我们也可以通过它来创建新的工程元素,在项目根目录下执行 `pnpm run new`:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
# 请选择你想要的操作
|
11
|
+
❯ 创建工程元素
|
12
|
+
启用可选功能
|
13
|
+
|
14
|
+
# 创建工程元素
|
15
|
+
❯ 新建「应用入口」
|
16
|
+
新建「Server 自定义」源码目录
|
17
|
+
|
18
|
+
# 请填写入口名称
|
19
|
+
- landing-page
|
20
|
+
|
21
|
+
# 是否需要调整默认配置
|
22
|
+
❯ 否
|
23
|
+
是
|
24
|
+
```
|
25
|
+
|
26
|
+
创建完成,项目会变成这样:
|
27
|
+
|
28
|
+
```md
|
29
|
+
.
|
30
|
+
├── .vscode/
|
31
|
+
├── src/
|
32
|
+
│ ├── hello-modern/
|
33
|
+
│ │ ├── components/
|
34
|
+
│ │ │ ├── Avatar/
|
35
|
+
│ │ │ │ ├── index.stories.tsx
|
36
|
+
│ │ │ │ └── index.tsx
|
37
|
+
│ │ │ └── Item/
|
38
|
+
│ │ │ ├── index.test.tsx
|
39
|
+
│ │ │ └── index.tsx
|
40
|
+
│ │ ├── styles/
|
41
|
+
│ │ │ └── utils.css
|
42
|
+
│ │ ├── App.css
|
43
|
+
│ │ └── App.tsx
|
44
|
+
│ ├── landing-page/
|
45
|
+
│ │ ├── App.css
|
46
|
+
│ │ └── App.tsx
|
47
|
+
│ ├── .eslintrc.json
|
48
|
+
│ └── modern-app-env.d.ts
|
49
|
+
├── .editorconfig
|
50
|
+
├── .gitignore
|
51
|
+
├── .npmrc
|
52
|
+
├── .nvmrc
|
53
|
+
├── README.md
|
54
|
+
├── package.json
|
55
|
+
├── pnpm-lock.yaml
|
56
|
+
└── tsconfig.json
|
57
|
+
```
|
58
|
+
|
59
|
+
可以看到联系人列表应用的文件,都被自动重构到 `src/hello-modern/` 里。
|
60
|
+
|
61
|
+
同时新建了一个 `src/landing-page/`,里面同样有 `App.tsx`(`pnpm run new` 命令只做了这些事,所以你也可以很容易的手动创建新入口或修改入口)
|
62
|
+
|
63
|
+
执行 `pnpm run dev`,显示:
|
64
|
+
|
65
|
+

|
66
|
+
|
67
|
+
访问 `http://localhost:8080/`,可以像之前一样看到联系人列表应用。
|
68
|
+
|
69
|
+
访问 `http://localhost:8080/landing-page`,可以看到刚创建的新入口 `landing-page` 的页面(Modern.js 自动生成的默认页面)。
|
70
|
+
|
71
|
+
## 手动调整应用入口
|
72
|
+
|
73
|
+
Modern.js 框架的设计原则之一是【[约定优于配置(Convention over Configuration)](https://en.wikipedia.org/wiki/Convention_over_configuration)】,多数情况下可以按约定直接写代码,不需要做任何配置,这里 `src/` 中的目录结构就是一种约定:
|
74
|
+
|
75
|
+
`src/hello-modern/` 和 `src/landing-page/` 被自动识别为两个应用入口:hello-modern 和 landing-page。
|
76
|
+
|
77
|
+
其中 `src/hello-modern/` 的目录名跟项目名(`package.json` 里的 `name`)一致,会被认为是项目**主入口**,项目 URL 的根路径(开发环境里默认是 `http://localhost:8080/`)会自动指向主入口。
|
78
|
+
|
79
|
+
其他入口的 URL,是在根路径后追加入口名,比如 `http://localhost:8080/landing-page`。
|
80
|
+
|
81
|
+
:::info 注
|
82
|
+
`src/` 下如果有 `App.[jt]sx`,就认为这个应用工程是单入口的,`src/` 下的其他文件和目录,都会被视为入口内部的文件。
|
83
|
+
|
84
|
+
`src/` 下如果没有 `App.[jt]sx`,那么 `src/` **下一级**目录里,如果有 `App.[jt]sx`,这个目录就会被视为一个应用入口。
|
85
|
+
|
86
|
+
`App.jsx` 被看作约定中**标识**,也有其他形式的**标识**,之后的章节中会继续介绍。
|
87
|
+
:::
|
88
|
+
|
89
|
+
接下来,我们把 `src/hello-modern/App.tsx` 重命名为 `src/contacts/App.tsx`:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
mv src/hello-modern src/contacts
|
93
|
+
```
|
94
|
+
|
95
|
+
再次执行 `pnpm run dev`,结果变成:
|
96
|
+
|
97
|
+

|
98
|
+
|
99
|
+
现在不再有主入口,联系人列表现在是一个普通入口,需要用 `http://localhost:8080/contacts` 访问。
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
> 本小节的代码可以在[这里查看](https://github.com/modern-js-dev/modern-js-examples/tree/main/tutorials/c07/hello-modern-2)。
|
104
|
+
|