@modern-js/app-tools 3.6.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/modern-bundle-docs.js +7 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
- package/dist/cjs/bundleDocs.js +114 -0
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/deploy.js +4 -2
- package/dist/cjs/commands/index.js +0 -4
- package/dist/cjs/config/default.js +2 -0
- package/dist/cjs/index.js +52 -14
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +3 -2
- package/dist/cjs/plugins/initialize/index.js +4 -3
- package/dist/cjs/plugins/serverBuild.js +3 -2
- package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm/bundleDocs.mjs +62 -0
- package/dist/esm/commands/build.mjs +2 -1
- package/dist/esm/commands/deploy.mjs +4 -2
- package/dist/esm/commands/index.mjs +0 -4
- package/dist/esm/config/default.mjs +2 -0
- package/dist/esm/index.mjs +15 -1
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +3 -2
- package/dist/esm/plugins/initialize/index.mjs +4 -3
- package/dist/esm/plugins/serverBuild.mjs +3 -2
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm-node/bundleDocs.mjs +63 -0
- package/dist/esm-node/commands/build.mjs +2 -1
- package/dist/esm-node/commands/deploy.mjs +4 -2
- package/dist/esm-node/commands/index.mjs +0 -4
- package/dist/esm-node/config/default.mjs +2 -0
- package/dist/esm-node/index.mjs +15 -1
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
- package/dist/esm-node/plugins/initialize/index.mjs +4 -3
- package/dist/esm-node/plugins/serverBuild.mjs +3 -2
- package/dist/types/bundleDocs.d.ts +20 -0
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/types/config/dev.d.ts +6 -0
- package/docs/apis/app/commands.md +241 -0
- package/docs/apis/app/hooks/api/lambda.md +9 -0
- package/docs/apis/app/hooks/config/favicon.md +24 -0
- package/docs/apis/app/hooks/config/html.md +5 -0
- package/docs/apis/app/hooks/config/icon.md +24 -0
- package/docs/apis/app/hooks/config/mock.md +6 -0
- package/docs/apis/app/hooks/config/public.md +26 -0
- package/docs/apis/app/hooks/config/upload.md +50 -0
- package/docs/apis/app/hooks/modern-config.md +5 -0
- package/docs/apis/app/hooks/server/server.md +5 -0
- package/docs/apis/app/hooks/shared.md +3 -0
- package/docs/apis/app/hooks/src/app.md +30 -0
- package/docs/apis/app/hooks/src/entry.md +34 -0
- package/docs/apis/app/hooks/src/entry.server.md +51 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
- package/docs/apis/app/hooks/src/routes.md +86 -0
- package/docs/apis/app/hooks/src/server.md +3 -0
- package/docs/apis/app/runtime/bff/use-hono-context.md +27 -0
- package/docs/apis/app/runtime/core/create-root.md +19 -0
- package/docs/apis/app/runtime/core/render.md +39 -0
- package/docs/apis/app/runtime/core/runtime-context.md +156 -0
- package/docs/apis/app/runtime/router/router.md +280 -0
- package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
- package/docs/apis/app/runtime/ssr/renderString.md +60 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
- package/docs/apis/app/runtime/utility/head.md +35 -0
- package/docs/apis/app/runtime/utility/loadable.md +82 -0
- package/docs/community/blog/2022-0708-updates.md +91 -0
- package/docs/community/blog/2022-0910-updates.md +76 -0
- package/docs/community/blog/overview.md +63 -0
- package/docs/community/blog/v2-release-note.md +238 -0
- package/docs/community/blog/v3-release-note.md +622 -0
- package/docs/community/contributing-guide.md +253 -0
- package/docs/community/releases.md +27 -0
- package/docs/community/showcase.md +34 -0
- package/docs/community/team.md +14 -0
- package/docs/configure/app/bff/cross-project.md +20 -0
- package/docs/configure/app/bff/prefix.md +29 -0
- package/docs/configure/app/builder-plugins.md +66 -0
- package/docs/configure/app/dev/asset-prefix.md +13 -0
- package/docs/configure/app/dev/before-start-url.md +17 -0
- package/docs/configure/app/dev/client.md +41 -0
- package/docs/configure/app/dev/hmr.md +10 -0
- package/docs/configure/app/dev/host.md +18 -0
- package/docs/configure/app/dev/https.md +77 -0
- package/docs/configure/app/dev/lazy-compilation.md +39 -0
- package/docs/configure/app/dev/live-reload.md +10 -0
- package/docs/configure/app/dev/mock-dir.md +31 -0
- package/docs/configure/app/dev/progress-bar.md +19 -0
- package/docs/configure/app/dev/server.md +124 -0
- package/docs/configure/app/dev/setup-middlewares.md +32 -0
- package/docs/configure/app/dev/start-url.md +48 -0
- package/docs/configure/app/dev/watch-files.md +27 -0
- package/docs/configure/app/dev/write-to-disk.md +10 -0
- package/docs/configure/app/experiments/source-build.md +31 -0
- package/docs/configure/app/html/app-icon.md +28 -0
- package/docs/configure/app/html/crossorigin.md +10 -0
- package/docs/configure/app/html/favicon.md +16 -0
- package/docs/configure/app/html/inject.md +10 -0
- package/docs/configure/app/html/meta.md +24 -0
- package/docs/configure/app/html/mount-id.md +10 -0
- package/docs/configure/app/html/output-structure.md +10 -0
- package/docs/configure/app/html/script-loading.md +10 -0
- package/docs/configure/app/html/tags.md +15 -0
- package/docs/configure/app/html/template-parameters.md +33 -0
- package/docs/configure/app/html/template.md +10 -0
- package/docs/configure/app/html/title.md +18 -0
- package/docs/configure/app/output/asset-prefix.md +11 -0
- package/docs/configure/app/output/assets-retry.md +77 -0
- package/docs/configure/app/output/charset.md +10 -0
- package/docs/configure/app/output/clean-dist-path.md +16 -0
- package/docs/configure/app/output/convert-to-rem.md +79 -0
- package/docs/configure/app/output/copy.md +10 -0
- package/docs/configure/app/output/css-modules.md +48 -0
- package/docs/configure/app/output/data-uri-limit.md +26 -0
- package/docs/configure/app/output/disable-css-module-extension.md +55 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
- package/docs/configure/app/output/disable-svgr.md +16 -0
- package/docs/configure/app/output/disable-ts-checker.md +49 -0
- package/docs/configure/app/output/dist-path.md +43 -0
- package/docs/configure/app/output/enable-asset-manifest.md +36 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
- package/docs/configure/app/output/externals.md +20 -0
- package/docs/configure/app/output/filename-hash.md +10 -0
- package/docs/configure/app/output/filename.md +55 -0
- package/docs/configure/app/output/inject-styles.md +10 -0
- package/docs/configure/app/output/inline-scripts.md +29 -0
- package/docs/configure/app/output/inline-styles.md +29 -0
- package/docs/configure/app/output/legal-comments.md +18 -0
- package/docs/configure/app/output/minify.md +22 -0
- package/docs/configure/app/output/override-browserslist.md +22 -0
- package/docs/configure/app/output/polyfill.md +12 -0
- package/docs/configure/app/output/source-map.md +30 -0
- package/docs/configure/app/output/split-route-chunks.md +16 -0
- package/docs/configure/app/output/ssg.md +81 -0
- package/docs/configure/app/output/ssgByEntries.md +90 -0
- package/docs/configure/app/output/svg-default-export.md +30 -0
- package/docs/configure/app/output/temp-dir.md +20 -0
- package/docs/configure/app/performance/build-cache.md +39 -0
- package/docs/configure/app/performance/chunk-split.md +40 -0
- package/docs/configure/app/performance/dns-prefetch.md +15 -0
- package/docs/configure/app/performance/preconnect.md +16 -0
- package/docs/configure/app/performance/prefetch.md +21 -0
- package/docs/configure/app/performance/preload.md +23 -0
- package/docs/configure/app/performance/print-file-size.md +40 -0
- package/docs/configure/app/performance/profile.md +10 -0
- package/docs/configure/app/performance/remove-console.md +10 -0
- package/docs/configure/app/performance/remove-moment-locale.md +10 -0
- package/docs/configure/app/plugins.md +59 -0
- package/docs/configure/app/resolve/alias-strategy.md +10 -0
- package/docs/configure/app/resolve/alias.md +9 -0
- package/docs/configure/app/resolve/condition-names.md +13 -0
- package/docs/configure/app/resolve/dedupe.md +9 -0
- package/docs/configure/app/resolve/extensions.md +13 -0
- package/docs/configure/app/runtime/0-intro.md +58 -0
- package/docs/configure/app/runtime/plugins.md +58 -0
- package/docs/configure/app/runtime/router.md +35 -0
- package/docs/configure/app/security/check-syntax.md +69 -0
- package/docs/configure/app/security/nonce.md +15 -0
- package/docs/configure/app/security/sri.md +20 -0
- package/docs/configure/app/server/base-url.md +26 -0
- package/docs/configure/app/server/port.md +18 -0
- package/docs/configure/app/server/public-routes.md +22 -0
- package/docs/configure/app/server/routes.md +86 -0
- package/docs/configure/app/server/rsc.md +26 -0
- package/docs/configure/app/server/ssr-by-entries.md +25 -0
- package/docs/configure/app/server/ssr.md +78 -0
- package/docs/configure/app/server/tsconfig-path.md +59 -0
- package/docs/configure/app/source/alias-strategy.md +14 -0
- package/docs/configure/app/source/alias.md +23 -0
- package/docs/configure/app/source/config-dir.md +20 -0
- package/docs/configure/app/source/decorators.md +25 -0
- package/docs/configure/app/source/define.md +16 -0
- package/docs/configure/app/source/disable-default-entries.md +28 -0
- package/docs/configure/app/source/enable-async-entry.md +54 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
- package/docs/configure/app/source/entries-dir.md +35 -0
- package/docs/configure/app/source/entries.md +179 -0
- package/docs/configure/app/source/exclude.md +10 -0
- package/docs/configure/app/source/global-vars.md +106 -0
- package/docs/configure/app/source/include.md +36 -0
- package/docs/configure/app/source/main-entry-name.md +24 -0
- package/docs/configure/app/source/pre-entry.md +10 -0
- package/docs/configure/app/source/react-compiler.md +68 -0
- package/docs/configure/app/source/transform-import.md +27 -0
- package/docs/configure/app/split-chunks.md +17 -0
- package/docs/configure/app/tools/autoprefixer.md +44 -0
- package/docs/configure/app/tools/bundler-chain.md +26 -0
- package/docs/configure/app/tools/css-extract.md +33 -0
- package/docs/configure/app/tools/css-loader.md +17 -0
- package/docs/configure/app/tools/dev-server.md +113 -0
- package/docs/configure/app/tools/html-plugin.md +41 -0
- package/docs/configure/app/tools/less.md +81 -0
- package/docs/configure/app/tools/lightningcss-loader.md +35 -0
- package/docs/configure/app/tools/minify-css.md +53 -0
- package/docs/configure/app/tools/postcss.md +34 -0
- package/docs/configure/app/tools/rspack.md +10 -0
- package/docs/configure/app/tools/sass.md +78 -0
- package/docs/configure/app/tools/style-loader.md +10 -0
- package/docs/configure/app/tools/swc.md +65 -0
- package/docs/configure/app/tools/ts-checker.md +109 -0
- package/docs/configure/app/usage.md +276 -0
- package/docs/guides/advanced-features/bff/cross-project.md +109 -0
- package/docs/guides/advanced-features/bff/extend-server.md +120 -0
- package/docs/guides/advanced-features/bff/frameworks.md +124 -0
- package/docs/guides/advanced-features/bff/function.md +314 -0
- package/docs/guides/advanced-features/bff/operators.md +554 -0
- package/docs/guides/advanced-features/bff/sdk.md +116 -0
- package/docs/guides/advanced-features/bff/upload.md +101 -0
- package/docs/guides/advanced-features/bff.md +18 -0
- package/docs/guides/advanced-features/build-performance.md +130 -0
- package/docs/guides/advanced-features/compatibility.md +120 -0
- package/docs/guides/advanced-features/international/advanced.md +128 -0
- package/docs/guides/advanced-features/international/api.md +231 -0
- package/docs/guides/advanced-features/international/best-practices.md +286 -0
- package/docs/guides/advanced-features/international/configuration.md +227 -0
- package/docs/guides/advanced-features/international/locale-detection.md +126 -0
- package/docs/guides/advanced-features/international/quick-start.md +128 -0
- package/docs/guides/advanced-features/international/resource-loading.md +154 -0
- package/docs/guides/advanced-features/international/routing.md +130 -0
- package/docs/guides/advanced-features/international.md +27 -0
- package/docs/guides/advanced-features/low-level.md +46 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +69 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
- package/docs/guides/advanced-features/source-build.md +164 -0
- package/docs/guides/advanced-features/web-server.md +288 -0
- package/docs/guides/basic-features/alias.md +102 -0
- package/docs/guides/basic-features/css/css-in-js.md +72 -0
- package/docs/guides/basic-features/css/css-modules.md +212 -0
- package/docs/guides/basic-features/css/css.md +27 -0
- package/docs/guides/basic-features/css/tailwindcss.md +27 -0
- package/docs/guides/basic-features/data/data-cache.md +510 -0
- package/docs/guides/basic-features/data/data-fetch.md +415 -0
- package/docs/guides/basic-features/data/data-write.md +227 -0
- package/docs/guides/basic-features/debug/mock.md +109 -0
- package/docs/guides/basic-features/debug/proxy.md +21 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +62 -0
- package/docs/guides/basic-features/debug/using-storybook.md +112 -0
- package/docs/guides/basic-features/deploy.md +458 -0
- package/docs/guides/basic-features/env-vars.md +177 -0
- package/docs/guides/basic-features/html.md +255 -0
- package/docs/guides/basic-features/output-files.md +141 -0
- package/docs/guides/basic-features/render/before-render.md +108 -0
- package/docs/guides/basic-features/render/overview.md +47 -0
- package/docs/guides/basic-features/render/rsc.md +525 -0
- package/docs/guides/basic-features/render/ssg.md +228 -0
- package/docs/guides/basic-features/render/ssr-cache.md +201 -0
- package/docs/guides/basic-features/render/ssr.md +321 -0
- package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
- package/docs/guides/basic-features/routes/config-routes.md +426 -0
- package/docs/guides/basic-features/routes/routes.md +498 -0
- package/docs/guides/basic-features/static-assets/json-files.md +120 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
- package/docs/guides/basic-features/static-assets.md +160 -0
- package/docs/guides/basic-features/testing/playwright.md +120 -0
- package/docs/guides/basic-features/testing/rstest.md +251 -0
- package/docs/guides/concept/builder.md +37 -0
- package/docs/guides/concept/entries.md +319 -0
- package/docs/guides/concept/server.md +35 -0
- package/docs/guides/get-started/ai-coding-agents.md +58 -0
- package/docs/guides/get-started/glossary.md +63 -0
- package/docs/guides/get-started/introduction.md +36 -0
- package/docs/guides/get-started/quick-start.md +236 -0
- package/docs/guides/get-started/tech-stack.md +82 -0
- package/docs/guides/get-started/upgrade.md +123 -0
- package/docs/guides/topic-detail/module-federation/application.md +116 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
- package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +118 -0
- package/docs/guides/topic-detail/module-federation/usage.md +219 -0
- package/docs/guides/troubleshooting/builder.md +110 -0
- package/docs/guides/troubleshooting/cli.md +35 -0
- package/docs/guides/troubleshooting/dependencies.md +119 -0
- package/docs/guides/troubleshooting/hmr.md +144 -0
- package/docs/guides/upgrade/config.md +963 -0
- package/docs/guides/upgrade/entry.md +463 -0
- package/docs/guides/upgrade/other.md +183 -0
- package/docs/guides/upgrade/overview.md +33 -0
- package/docs/guides/upgrade/tailwindcss.md +91 -0
- package/docs/guides/upgrade/web-server.md +109 -0
- package/docs/index.md +33 -0
- package/docs/llms.txt +285 -0
- package/docs/plugin/cli-plugins/api.md +573 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +152 -0
- package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
- package/docs/plugin/official/cli-plugins.md +4 -0
- package/docs/plugin/plugin-system.md +238 -0
- package/docs/plugin/runtime-plugins/api.md +194 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +209 -0
- package/docs/plugin/server-plugins/life-cycle.md +13 -0
- package/docs/tutorials/examples/csr-auth.md +9 -0
- package/docs/tutorials/foundations/introduction.md +16 -0
- package/package.json +48 -15
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# tools.tsChecker
|
|
2
|
+
|
|
3
|
+
- **Type:** `Object | Function`
|
|
4
|
+
- **Default:**
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
typescript: {
|
|
9
|
+
// set 'readonly' to avoid emitting tsbuildinfo,
|
|
10
|
+
// as the generated tsbuildinfo will break ts-checker-rspack-plugin
|
|
11
|
+
mode: 'readonly',
|
|
12
|
+
// enable build when using project reference
|
|
13
|
+
build: useReference,
|
|
14
|
+
// avoid OOM issue
|
|
15
|
+
memoryLimit: 8192,
|
|
16
|
+
// use tsconfig of user project
|
|
17
|
+
configFile: tsconfigPath,
|
|
18
|
+
// resolve the default TypeScript package from user project
|
|
19
|
+
resolveRoot: rootPath,
|
|
20
|
+
},
|
|
21
|
+
issue: {
|
|
22
|
+
// ignore type errors from node_modules
|
|
23
|
+
exclude: [({ file = '' }) => /[\\/]node_modules[\\/]/.test(file)],
|
|
24
|
+
},
|
|
25
|
+
logger: {
|
|
26
|
+
log() {
|
|
27
|
+
// do nothing
|
|
28
|
+
// we only want to display error messages
|
|
29
|
+
},
|
|
30
|
+
error(message: string) {
|
|
31
|
+
console.error(
|
|
32
|
+
message
|
|
33
|
+
.replace(/ERROR/g, 'Type Error')
|
|
34
|
+
.replace(/WARNING/g, 'Type Warning'),
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
By default, the [@rsbuild/plugin-type-check](https://github.com/rstackjs/rsbuild-plugin-type-check) is enabled for type checking. You can use `output.disableTsChecker` config to disable it.
|
|
42
|
+
|
|
43
|
+
## Example
|
|
44
|
+
|
|
45
|
+
### Object Type
|
|
46
|
+
|
|
47
|
+
When the value of `tsChecker` is an object, it will be deeply merged with the default configuration.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export default {
|
|
51
|
+
tools: {
|
|
52
|
+
tsChecker: {
|
|
53
|
+
issue: {
|
|
54
|
+
exclude: [({ file = '' }) => /[\\/]some-folder[\\/]/.test(file)],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Function Type
|
|
62
|
+
|
|
63
|
+
When the value of `tsChecker` is a function, the default configuration will be passed as the first argument. You can directly modify the configuration object or return an object as the final configuration.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
export default {
|
|
67
|
+
tools: {
|
|
68
|
+
tsChecker(options) {
|
|
69
|
+
options.async = false;
|
|
70
|
+
return options;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
> Please refer to [@rsbuild/plugin-type-check](https://github.com/rstackjs/rsbuild-plugin-type-check) for more details.
|
|
77
|
+
|
|
78
|
+
## TypeScript 7+ Support
|
|
79
|
+
|
|
80
|
+
`tools.tsChecker` supports the native checker included in TypeScript 7+. This capability is provided by [`ts-checker-rspack-plugin`](https://github.com/rstackjs/ts-checker-rspack-plugin), which is integrated by [`@rsbuild/plugin-type-check`](https://github.com/rstackjs/rsbuild-plugin-type-check), and can reduce type-checking time on large projects.
|
|
81
|
+
|
|
82
|
+
Install TypeScript >= 7.0.0 to enable `tsgo` automatically:
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
```sh [npm]
|
|
86
|
+
npm install typescript@latest -D
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```sh [yarn]
|
|
90
|
+
yarn add typescript@latest -D
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```sh [pnpm]
|
|
94
|
+
pnpm add typescript@latest -D
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```sh [bun]
|
|
98
|
+
bun add typescript@latest -D
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```sh [deno]
|
|
102
|
+
deno add npm:typescript@latest -D
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
When `tsgo` is enabled and `typescript.typescriptPath` is set manually, it must point to an absolute TypeScript 7+ `typescript/package.json` path or the legacy `@typescript/native-preview/package.json` path.
|
|
106
|
+
|
|
107
|
+
> The `@typescript/native-preview` path is kept only for compatibility. New setups should use TypeScript 7+ from the standard `typescript` package.
|
|
108
|
+
|
|
109
|
+
For supported options and limitations, please refer to [ts-checker-rspack-plugin - TypeScript 7+ support](https://github.com/rstackjs/ts-checker-rspack-plugin#typescript-7-support).
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
There are three types of configurations in Modern.js: Compile configuration, Runtime configuration, and Server Runtime configuration.
|
|
4
|
+
|
|
5
|
+
**Compile configuration** can be configured in two locations:
|
|
6
|
+
|
|
7
|
+
- The `modern.config.(ts|js|mjs)` file at the root path
|
|
8
|
+
- The `package.json` file
|
|
9
|
+
|
|
10
|
+
:::info
|
|
11
|
+
Modern.js does not support configuring the same configuration item in both `package.json` and `modern.config.ts` simultaneously. It is recommended to configure it in `modern.config.ts`. If Modern.js detects conflicts due to duplicate configurations, it will throw a warning.
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
**Runtime configuration** can be configured in the `src/modern.runtime.(ts|js|mjs)` file.
|
|
15
|
+
|
|
16
|
+
**Server Runtime configuration** can be configured in the `server/modern.server.(ts|js|mjs)` file.
|
|
17
|
+
|
|
18
|
+
## Compile Configuration
|
|
19
|
+
|
|
20
|
+
### Configuring in Configuration Files
|
|
21
|
+
|
|
22
|
+
The configuration files for Modern.js are defined in the root directory of the project and support `.ts`, `.js`, and `.mjs` formats:
|
|
23
|
+
|
|
24
|
+
- `modern.config.ts`
|
|
25
|
+
- `modern.config.js`
|
|
26
|
+
- `modern.config.mjs`
|
|
27
|
+
|
|
28
|
+
#### modern.config.ts (Recommended)
|
|
29
|
+
|
|
30
|
+
We recommend using the `.ts` format for configuration files as it provides friendly TypeScript type hints, helping you avoid errors in the configuration.
|
|
31
|
+
|
|
32
|
+
Import the `defineConfig` utility function from `@modern-js/app-tools`, which will assist you with type inference and type completion for the configuration:
|
|
33
|
+
|
|
34
|
+
```ts title="modern.config.ts"
|
|
35
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
source: {
|
|
39
|
+
alias: {
|
|
40
|
+
'@common': './src/common',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### modern.config.js
|
|
47
|
+
|
|
48
|
+
If you are developing a non-TypeScript project, you can use the `.js` format for the configuration file:
|
|
49
|
+
|
|
50
|
+
```js title="modern.config.js"
|
|
51
|
+
export default {
|
|
52
|
+
source: {
|
|
53
|
+
alias: opts => {
|
|
54
|
+
opts['@common'] = './src/common';
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also configure different settings based on the environment using `process.env.NODE_ENV`:
|
|
61
|
+
|
|
62
|
+
```js title="modern.config.js"
|
|
63
|
+
export default {
|
|
64
|
+
server: {
|
|
65
|
+
ssr: process.env.NODE_ENV === 'development',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Exporting Configuration Functions
|
|
71
|
+
|
|
72
|
+
Modern.js supports exporting a function in the configuration file, where you can dynamically compute the configuration and return it to Modern.js.
|
|
73
|
+
|
|
74
|
+
```js title="modern.config.js"
|
|
75
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
76
|
+
|
|
77
|
+
export default defineConfig(({ env, command }) => ({
|
|
78
|
+
source: {
|
|
79
|
+
alias: {
|
|
80
|
+
'@foo': env === 'development' ? './src/foo.dev.ts' : './src/foo.prod.ts',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}));
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This function accepts the following parameters:
|
|
87
|
+
|
|
88
|
+
- `env`: Corresponds to the value of `process.env.NODE_ENV`.
|
|
89
|
+
- When running `modern dev`, the value of `env` is `development`.
|
|
90
|
+
- When running `modern build` or `modern serve`, the value of `env` is `production`.
|
|
91
|
+
- `command`: Corresponds to the current command being run, such as `dev`, `build`, or `serve`.
|
|
92
|
+
|
|
93
|
+
#### Exporting Asynchronous Functions
|
|
94
|
+
|
|
95
|
+
Modern.js also supports exporting an asynchronous function in the configuration file, allowing you to perform some asynchronous operations:
|
|
96
|
+
|
|
97
|
+
```js title="modern.config.js"
|
|
98
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
99
|
+
|
|
100
|
+
export default defineConfig(async ({ env, command }) => {
|
|
101
|
+
const result = await someAsyncFunction();
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
html: {
|
|
105
|
+
title: result,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Specifying Configuration Files
|
|
112
|
+
|
|
113
|
+
The Modern.js command line supports specifying the name of the configuration file using the `--config` option.
|
|
114
|
+
|
|
115
|
+
For example, if you need to use the `modern.prod.config.js` file when executing the `build` command, you can add the following configuration in `package.json`:
|
|
116
|
+
|
|
117
|
+
```json title="package.json"
|
|
118
|
+
{
|
|
119
|
+
"scripts": {
|
|
120
|
+
"dev": "modern dev",
|
|
121
|
+
"build": "modern build --config modern.prod.config.js"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
You can also abbreviate the `--config` option as `-c`:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
$ modern build -c modern.prod.config.js
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Configuring in package.json (Not Recommended)
|
|
133
|
+
|
|
134
|
+
In addition to configuration files, you can also set configuration items under the `modernConfig` field in `package.json`, such as:
|
|
135
|
+
|
|
136
|
+
```json title="package.json"
|
|
137
|
+
{
|
|
138
|
+
"modernConfig": {
|
|
139
|
+
"source": {
|
|
140
|
+
"alias": {
|
|
141
|
+
"@common": "./src/common"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Due to the limitations of the JSON file format, only simple types such as numbers, strings, booleans, and arrays can be defined in `package.json`. When we need to set function-type values, it is recommended to do so in the Modern.js configuration file.
|
|
149
|
+
|
|
150
|
+
#### Notes
|
|
151
|
+
|
|
152
|
+
- It is not recommended to use both `package.json` and `modern.config.js` for configuration simultaneously. If both are used and conflicts arise, Modern.js will prompt an error in the command line.
|
|
153
|
+
|
|
154
|
+
### Local Debugging Configuration
|
|
155
|
+
|
|
156
|
+
To facilitate local debugging of configurations, Modern.js supports creating a `modern.config.local.(ts|js|mjs)` file in the root directory to override the configuration options in `modern.config.(ts|js|mjs)`.
|
|
157
|
+
|
|
158
|
+
#### Example
|
|
159
|
+
|
|
160
|
+
For example, if the `modern.config.ts` file in your project is configured with a port number of `3000`:
|
|
161
|
+
|
|
162
|
+
```ts title="modern.config.ts"
|
|
163
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
164
|
+
|
|
165
|
+
export default defineConfig({
|
|
166
|
+
server: {
|
|
167
|
+
port: 3000,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
If you need to change the port number to `3001` for local debugging but do not want to modify the current project's `modern.config.ts` file, you can create a `modern.config.local.ts` file and add the following configuration:
|
|
173
|
+
|
|
174
|
+
```ts title="modern.config.local.ts"
|
|
175
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
176
|
+
|
|
177
|
+
export default defineConfig({
|
|
178
|
+
server: {
|
|
179
|
+
port: 3001,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The configuration in the `modern.config.local.ts` file will be deeply merged with the configuration in `modern.config.ts`, overriding the options in `modern.config.ts`, so `server.port` will be changed to `3001`.
|
|
185
|
+
|
|
186
|
+
#### Notes
|
|
187
|
+
|
|
188
|
+
When using `modern.config.local.ts`, please note the following:
|
|
189
|
+
|
|
190
|
+
- The `modern.config.local.ts` file will only be loaded when executing the `modern dev` commands and will not be loaded during `modern build`.
|
|
191
|
+
- The priority of the `modern.config.local.ts` file is higher than both `modern.config.ts` and the `modernConfig` field in `package.json`.
|
|
192
|
+
- Since `modern.config.local.ts` is only used for local debugging, it is not recommended to commit it to the code repository. Ensure that the project's `.gitignore` file includes `modern.config.local.ts` and similar files.
|
|
193
|
+
|
|
194
|
+
```bash title=".gitignore"
|
|
195
|
+
modern.config.local.*
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Merging Multiple Configurations
|
|
199
|
+
|
|
200
|
+
In some cases, you may need to merge multiple configurations into one. You can use the `mergeConfig` utility function to merge multiple configurations.
|
|
201
|
+
|
|
202
|
+
The `mergeConfig` function accepts an array as a parameter, where each item in the array is a configuration object. `mergeConfig` will deeply merge each configuration object in the array, automatically merging multiple function items into an array, and finally returning a merged configuration object.
|
|
203
|
+
|
|
204
|
+
#### Example
|
|
205
|
+
|
|
206
|
+
```ts title="modern.config.ts"
|
|
207
|
+
import { mergeConfig } from '@modern-js/app-tools';
|
|
208
|
+
|
|
209
|
+
const config1 = {
|
|
210
|
+
dev: {
|
|
211
|
+
port: 3000,
|
|
212
|
+
},
|
|
213
|
+
tools: {
|
|
214
|
+
postcss: () => console.log('config1');
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
const config2 = {
|
|
218
|
+
dev: {
|
|
219
|
+
port: 3001,
|
|
220
|
+
},
|
|
221
|
+
tools: {
|
|
222
|
+
postcss: () => console.log('config2');
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const mergedConfig = mergeConfig([config1, config2]);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
In the above example, the merged configuration object will be:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const mergedConfig = {
|
|
233
|
+
dev: {
|
|
234
|
+
port: 3001,
|
|
235
|
+
},
|
|
236
|
+
tools: {
|
|
237
|
+
postcss: [() => console.log('config1'), () => console.log('config2')],
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Configuration Type Definitions
|
|
243
|
+
|
|
244
|
+
Modern.js exports the `AppUserConfig` type, which corresponds to the type of the Modern.js configuration object:
|
|
245
|
+
|
|
246
|
+
```ts title="modern.config.ts"
|
|
247
|
+
import type { AppUserConfig } from '@modern-js/app-tools';
|
|
248
|
+
|
|
249
|
+
const config: AppUserConfig = {
|
|
250
|
+
tools: {
|
|
251
|
+
rspack: {},
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Runtime Configuration
|
|
257
|
+
|
|
258
|
+
For detailed information on runtime configuration, please refer to the [Introduction to Runtime Configuration](/configure/app/runtime/0-intro.md).
|
|
259
|
+
|
|
260
|
+
:::tip
|
|
261
|
+
If the current Runtime configuration needs to be used both at compile time and runtime, please add the relevant configuration parameters at the plugin registration location.
|
|
262
|
+
|
|
263
|
+
```ts title="modern.config.ts"
|
|
264
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
265
|
+
import { xxPlugin } from '@modern-js/plugin-xx';
|
|
266
|
+
|
|
267
|
+
export default defineConfig({
|
|
268
|
+
plugins: [
|
|
269
|
+
xxPlugin({
|
|
270
|
+
/** Add parameters here */
|
|
271
|
+
}),
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
:::
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Cross-Project Invocation
|
|
2
|
+
|
|
3
|
+
Based on the BFF architecture, Modern.js provides cross-project invocation capabilities, allowing BFF functions created in one project to be invoked by other projects through integrated calls, enabling function sharing and feature reuse across projects.
|
|
4
|
+
Cross-project invocation consists of **producer** and **consumer** sides. The producer is responsible for creating and providing BFF services while generating integrated invocation SDK, and the consumer initiates requests through these SDK.
|
|
5
|
+
|
|
6
|
+
## BFF Producer
|
|
7
|
+
|
|
8
|
+
Enable cross-project invocation via configuration. Projects with BFF capabilities enabled can act as BFF producers, or you can create standalone BFF applications.
|
|
9
|
+
When executing `dev` or `build`, the following artifacts for consumers will be automatically generated:
|
|
10
|
+
|
|
11
|
+
- API functions under the `dist/client` directory
|
|
12
|
+
- Runtime configuration functions under the `dist/runtime` directory
|
|
13
|
+
- Interface exports defined in `exports` field of `package.json`
|
|
14
|
+
- File list for npm publication specified in `files` field of `package.json`
|
|
15
|
+
|
|
16
|
+
### Existing BFF-enabled Projects
|
|
17
|
+
|
|
18
|
+
1. Enable Cross-Project Invocation
|
|
19
|
+
|
|
20
|
+
Ensure the current project has BFF enabled with API files defined under `api/lambda`. Add the following configuration:
|
|
21
|
+
|
|
22
|
+
```ts title="modern.config.ts"
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
bff: {
|
|
25
|
+
crossProject: true,
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. Generate SDK Type Files
|
|
31
|
+
|
|
32
|
+
To provide type hints for the integrated invocation SDK, enable the `declaration` option in TypeScript configuration:
|
|
33
|
+
|
|
34
|
+
```ts title="tsconfig.json"
|
|
35
|
+
"compilerOptions": {
|
|
36
|
+
"declaration": true,
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## BFF Consumer
|
|
41
|
+
|
|
42
|
+
:::info
|
|
43
|
+
You can initiate requests to BFF producers from projects using any framework via the SDK.
|
|
44
|
+
:::
|
|
45
|
+
|
|
46
|
+
### Intra-Monorepo Invocation
|
|
47
|
+
|
|
48
|
+
When producer and consumer are in the same Monorepo, directly import the SDK. API functions reside under `${package_name}/api`:
|
|
49
|
+
|
|
50
|
+
```ts title="src/routes/page.tsx"
|
|
51
|
+
import { useState, useEffect } from 'react';
|
|
52
|
+
import { get as hello } from '${package_name}/api/hello';
|
|
53
|
+
|
|
54
|
+
export default () => {
|
|
55
|
+
const [text, setText] = useState('');
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
hello().then(setText);
|
|
59
|
+
}, []);
|
|
60
|
+
return <div>{text}</div>;
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Cross-Project Invocation
|
|
65
|
+
|
|
66
|
+
When producer and consumer are in separate repositories, publish the BFF producer as an npm package. The invocation method remains the same as intra-Monorepo.
|
|
67
|
+
|
|
68
|
+
### Domain Configuration and Extensions
|
|
69
|
+
|
|
70
|
+
For real-world scenarios requiring custom BFF service domains, use the configuration function:
|
|
71
|
+
|
|
72
|
+
```ts title="src/routes/page.tsx"
|
|
73
|
+
import { configure } from '${package_name}/runtime';
|
|
74
|
+
|
|
75
|
+
configure({
|
|
76
|
+
setDomain() {
|
|
77
|
+
return 'https://your-bff-api.com';
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `configure` function from `${package_name}/runtime` supports domain configuration via `setDomain`, interceptors, and custom SDK. When extending both **current project** and **cross-project** SDK on the same page:
|
|
83
|
+
|
|
84
|
+
```ts title="src/routes/page.tsx"
|
|
85
|
+
import { configure } from '${package_name}/runtime';
|
|
86
|
+
import { configure as innerConfigure } from '@modern-js/plugin-bff/client';
|
|
87
|
+
import axios from 'axios';
|
|
88
|
+
|
|
89
|
+
configure({
|
|
90
|
+
setDomain() {
|
|
91
|
+
return 'https://your-bff-api.com';
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
innerConfigure({
|
|
96
|
+
async request(...config: Parameters<typeof fetch>) {
|
|
97
|
+
const [url, params] = config;
|
|
98
|
+
const res = await axios({
|
|
99
|
+
url: url as string,
|
|
100
|
+
method: params?.method as Method,
|
|
101
|
+
data: params?.body,
|
|
102
|
+
headers: {
|
|
103
|
+
'x-header': 'innerConfigure',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return res.data;
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Extend BFF Server
|
|
2
|
+
|
|
3
|
+
In some applications, developers may want to handle all BFF functions uniformly, such as authentication, logging, data processing, etc.
|
|
4
|
+
|
|
5
|
+
Modern.js allows users to freely extend the BFF Server through [Middleware](/guides/advanced-features/web-server.md#middleware) method.
|
|
6
|
+
|
|
7
|
+
## Using Middleware
|
|
8
|
+
|
|
9
|
+
:::tip Version Consistency
|
|
10
|
+
Before using middleware, you need to install the `@modern-js/server-runtime` dependency. Make sure the version of `@modern-js/server-runtime` matches the version of `@modern-js/app-tools` in your project. All Modern.js official packages are released with a uniform version number, and version mismatches may cause compatibility issues.
|
|
11
|
+
|
|
12
|
+
Check the version of `@modern-js/app-tools` first, then install the same version of `@modern-js/server-runtime`:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Check the current version of @modern-js/app-tools
|
|
16
|
+
pnpm list @modern-js/app-tools
|
|
17
|
+
|
|
18
|
+
# Install the same version of @modern-js/server-runtime
|
|
19
|
+
pnpm add @modern-js/server-runtime@<version>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
Developers can use middleware by configuring middlewares in `server/modern.server.ts`. The following describes how to write a BFF middleware manually to add permission verification:
|
|
25
|
+
|
|
26
|
+
```ts title="server/modern.server.ts"
|
|
27
|
+
import {
|
|
28
|
+
type MiddlewareHandler,
|
|
29
|
+
defineServerConfig,
|
|
30
|
+
getCookie,
|
|
31
|
+
} from '@modern-js/server-runtime';
|
|
32
|
+
|
|
33
|
+
const requireAuthForApi: MiddlewareHandler = async (c, next) => {
|
|
34
|
+
if (c.req.path.startsWith('/api') && c.req.path !== '/api/login') {
|
|
35
|
+
const sid = getCookie(c, 'sid');
|
|
36
|
+
if (!sid) {
|
|
37
|
+
return c.json({ code: -1, message: 'need login' }, 400);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
await next();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default defineServerConfig({
|
|
44
|
+
middlewares: [
|
|
45
|
+
{
|
|
46
|
+
name: 'require-auth-for-api',
|
|
47
|
+
handler: requireAuthForApi,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then add a regular BFF function `api/lambda/hello.ts`:
|
|
54
|
+
|
|
55
|
+
```ts title="api/lambda/hello.ts"
|
|
56
|
+
export default async () => {
|
|
57
|
+
return 'Hello Modern.js';
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Next, in the frontend `src/routes/page.tsx`, add the interface access code and directly use the integrated method to call:
|
|
62
|
+
|
|
63
|
+
```ts title="src/routes/page.tsx"
|
|
64
|
+
import { useState, useEffect } from 'react';
|
|
65
|
+
import { get as hello } from '@api/hello';
|
|
66
|
+
|
|
67
|
+
export default () => {
|
|
68
|
+
const [text, setText] = useState('');
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
async function fetchMyApi() {
|
|
72
|
+
const { message } = await hello();
|
|
73
|
+
setText(message);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fetchMyApi();
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
return <p>{text}</p>;
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Now run the `dev` command to start the project, and access `http://localhost:8080/` to find that the request for `/api/hello` has been intercepted:
|
|
84
|
+
|
|
85
|
+

|
|
86
|
+
|
|
87
|
+
Finally, modify the frontend code `src/routes/page.tsx`, and call the login interface before accessing `/api/hello`:
|
|
88
|
+
|
|
89
|
+
:::note
|
|
90
|
+
This part does not implement a real login interface; the code is just for demonstration.
|
|
91
|
+
:::
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { useState, useEffect } from 'react';
|
|
95
|
+
import { get as hello } from '@api/hello';
|
|
96
|
+
import { post as login } from '@api/login';
|
|
97
|
+
|
|
98
|
+
export default () => {
|
|
99
|
+
const [text, setText] = useState('');
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
async function fetchAfterLogin() {
|
|
103
|
+
const { code } = await login();
|
|
104
|
+
if (code === 0) {
|
|
105
|
+
const { message } = await hello();
|
|
106
|
+
setText(message);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
fetchAfterLogin();
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
return <p>{text}</p>;
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Refresh the page, and you can see that the access to `/api/hello` is successful:
|
|
117
|
+
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
The above code simulates defining middleware in `server/Modern.server.ts` and implements a simple login function. Similarly, other functionalities can be implemented in this configuration file to extend the BFF Server.
|