@modern-js/app-tools 3.7.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 +46 -13
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Introduce
|
|
2
|
+
|
|
3
|
+
Modern.js runtime configuration should be centralized in the `src/modern.runtime.ts` file.
|
|
4
|
+
|
|
5
|
+
:::info
|
|
6
|
+
|
|
7
|
+
If this file doesn't exist in your project yet, create it with the following command:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
touch src/modern.runtime.ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
:::
|
|
14
|
+
|
|
15
|
+
## Basic Configuration
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
19
|
+
|
|
20
|
+
export default defineRuntimeConfig({
|
|
21
|
+
router: {
|
|
22
|
+
// Router configuration
|
|
23
|
+
},
|
|
24
|
+
// Other runtime modules...
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Multi-Entry Configuration
|
|
29
|
+
|
|
30
|
+
For multi-entry applications, `defineRuntimeConfig` can accept a function that returns specific configurations based on the entry name:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
34
|
+
|
|
35
|
+
export default defineRuntimeConfig(entryName => {
|
|
36
|
+
if (entryName === 'main') {
|
|
37
|
+
return {
|
|
38
|
+
router: {
|
|
39
|
+
// Router configuration for "main" entry
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Configuration for other entries
|
|
45
|
+
return {
|
|
46
|
+
router: {
|
|
47
|
+
// Other entry router configuration
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
:::tip
|
|
54
|
+
|
|
55
|
+
Using the `src/modern.runtime.ts` configuration approach does not support exporting asynchronous functions, which is related to the rendering method of Modern.js. If you need to add asynchronous logic, please use the **[Runtime Plugin](/plugin/introduction.md#runtime-plugin)**.
|
|
56
|
+
|
|
57
|
+
:::
|
|
58
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# plugins
|
|
2
|
+
|
|
3
|
+
- **Type:** `RuntimePlugin[]`
|
|
4
|
+
- **Default:** `[]`
|
|
5
|
+
|
|
6
|
+
Used to configure custom Modern.js Runtime plugins. For details on how to create custom Runtime plugins, please refer to [How to Write Runtime Plugins](/plugin/introduction.md#runtime-plugins).
|
|
7
|
+
|
|
8
|
+
:::info
|
|
9
|
+
|
|
10
|
+
Runtime plugins must be configured in the `plugins` array within the `src/modern.runtime.ts` file.
|
|
11
|
+
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
## Examples
|
|
15
|
+
|
|
16
|
+
Here are examples demonstrating how to use Runtime plugins:
|
|
17
|
+
|
|
18
|
+
### Using plugins from npm packages
|
|
19
|
+
|
|
20
|
+
To use plugins published on npm, first install them via your package manager, then import them into your configuration.
|
|
21
|
+
|
|
22
|
+
```ts title="src/modern.runtime.ts"
|
|
23
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
24
|
+
import { myPlugin } from 'my-plugin';
|
|
25
|
+
|
|
26
|
+
export default defineRuntimeConfig({
|
|
27
|
+
plugins: [myPlugin()],
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Using local plugins
|
|
32
|
+
|
|
33
|
+
To use plugins from your local codebase, import them directly using relative paths.
|
|
34
|
+
|
|
35
|
+
```ts title="src/modern.runtime.ts"
|
|
36
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
37
|
+
import { myPlugin } from './config/plugin/myPlugin';
|
|
38
|
+
|
|
39
|
+
export default defineRuntimeConfig({
|
|
40
|
+
plugins: [myPlugin()],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Plugin configuration
|
|
45
|
+
|
|
46
|
+
If a plugin supports custom configuration options, you can provide them as arguments to the plugin function.
|
|
47
|
+
|
|
48
|
+
```ts title="src/modern.runtime.ts"
|
|
49
|
+
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
50
|
+
import { myPlugin } from './config/plugin/myPlugin';
|
|
51
|
+
|
|
52
|
+
export default defineRuntimeConfig({
|
|
53
|
+
plugins: [myPlugin({
|
|
54
|
+
foo: 1,
|
|
55
|
+
bar: 2,
|
|
56
|
+
})],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# router
|
|
2
|
+
|
|
3
|
+
- **Type:** `Object`
|
|
4
|
+
- **Default:** `{}`
|
|
5
|
+
|
|
6
|
+
This configuration item is used to configure client-side routing, supporting the use of [conventional routing](/guides/concept/entries.md#convention-routing) provided by Modern.js for routing management.
|
|
7
|
+
|
|
8
|
+
:::note
|
|
9
|
+
The `router` configuration item **only takes effect when using conventional routing entries** (i.e., when there is a `routes/` directory in the entry). For controlled routing entries or custom entries, this configuration will not take effect.
|
|
10
|
+
|
|
11
|
+
In multi-entry applications, you can configure different routing behaviors for different entries using the function form of `defineRuntimeConfig`. For more details, see [Runtime Configuration Introduction](/configure/app/runtime/0-intro.md#multi-entry-configuration).
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
## basename
|
|
15
|
+
|
|
16
|
+
- **Type:** `string`
|
|
17
|
+
- **Default:** `/`
|
|
18
|
+
|
|
19
|
+
Sets the `basename` for client-side routing, typically used when the application needs to be deployed under a non-root path of the domain.
|
|
20
|
+
|
|
21
|
+
:::tip
|
|
22
|
+
It is recommended to use [`server.baseUrl`](/configure/app/server/base-url.md) for configuration.
|
|
23
|
+
:::
|
|
24
|
+
|
|
25
|
+
## supportHtml5History
|
|
26
|
+
|
|
27
|
+
- **Type:** `boolean`
|
|
28
|
+
- **Default:** `true`
|
|
29
|
+
|
|
30
|
+
If the value of `supportHtml5History` is `true`, `BrowserRouter` would be used, otherwise `HashRouter` would be used. `BrowserRouter` is recommended.
|
|
31
|
+
|
|
32
|
+
:::warning
|
|
33
|
+
When SSR is enabled, `supportHtml5History` is not supported.
|
|
34
|
+
|
|
35
|
+
:::
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# security.checkSyntax
|
|
2
|
+
|
|
3
|
+
- **Type:**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type CheckSyntax =
|
|
7
|
+
| boolean
|
|
8
|
+
| {
|
|
9
|
+
targets?: string[];
|
|
10
|
+
exclude?: RegExp | RegExp[];
|
|
11
|
+
ecmaVersion?: EcmaVersion;
|
|
12
|
+
};
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- **Default:** `false`
|
|
16
|
+
|
|
17
|
+
Used to analyze whether there is incompatible advanced syntax in the build artifacts under the current browser scope. If any incompatible syntax is found, detailed information will be printed to the terminal.
|
|
18
|
+
|
|
19
|
+
### Enable Detection
|
|
20
|
+
|
|
21
|
+
You can set `checkSyntax` to `true` to enable syntax checking.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export default {
|
|
25
|
+
security: {
|
|
26
|
+
checkSyntax: true,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
When you enable `checkSyntax`, Modern.js will perform the detection during production builds. If any incompatible advanced syntax is detected in the build artifacts, error logs will be printed to the terminal, and the current build process will be terminated.
|
|
32
|
+
|
|
33
|
+
### Error Logs
|
|
34
|
+
|
|
35
|
+
The format of the error logs is as follows, including the source file, artifact location, error reason, and source code:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
error [Syntax Checker] Find some syntax errors after production build:
|
|
39
|
+
|
|
40
|
+
Error 1
|
|
41
|
+
source: /node_modules/foo/index.js:1:0
|
|
42
|
+
output: /dist/static/js/main.3f7a4d7e.js:2:39400
|
|
43
|
+
reason: Unexpected token (1:178)
|
|
44
|
+
code:
|
|
45
|
+
9 |
|
|
46
|
+
10 | var b = 2;
|
|
47
|
+
11 |
|
|
48
|
+
> 12 | console.log(() => {
|
|
49
|
+
13 | return a + b;
|
|
50
|
+
14 | });
|
|
51
|
+
15 |
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
:::tip
|
|
55
|
+
Currently, syntax checking is implemented based on AST parser. Each time it performs a check, it can only identify the first incompatible syntax found in the file. If there are multiple incompatible syntaxes in the file, you need to fix the detected syntax and re-run the check.
|
|
56
|
+
If the corresponding source location is not shown in the log, try setting **output.minify** to false and rebuild again.
|
|
57
|
+
:::
|
|
58
|
+
|
|
59
|
+
### Solutions
|
|
60
|
+
|
|
61
|
+
If a syntax error is detected, you can handle it in the following ways:
|
|
62
|
+
|
|
63
|
+
- If you want to downgrade this syntax to ensure good code compatibility, you can compile the corresponding module through the `source.include` config.
|
|
64
|
+
- If you don't want to downgrade the syntax, you can adjust the project's browserslist to match the syntax.
|
|
65
|
+
- If you do not want to check the syntax of certain products, you can use the `checkSyntax.exclude` configuration to exclude the files to be checked.
|
|
66
|
+
|
|
67
|
+
### Options
|
|
68
|
+
|
|
69
|
+
`security.checkSyntax` is implemented based on `@rsbuild/plugin-check-syntax`. For specific options, please refer to [@rsbuild/plugin-check-syntax](https://github.com/rstackjs/rsbuild-plugin-check-syntax).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# security.nonce
|
|
2
|
+
|
|
3
|
+
- **Type:**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type Nonce = string;
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
- **Default:** `undefined`
|
|
10
|
+
|
|
11
|
+
Adding a `nonce` attribute to the scripts resources introduced for HTML. This allows the browser to determine whether the script can be executed when it parses inline scripts with matching nonce values.
|
|
12
|
+
|
|
13
|
+
:::info
|
|
14
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - security.nonce](https://v2.rsbuild.dev/config/security/nonce).
|
|
15
|
+
:::
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# security.sri
|
|
2
|
+
|
|
3
|
+
- **Type**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type SriOptions = {
|
|
7
|
+
hashFuncNames?: [string, ...string[]];
|
|
8
|
+
enabled?: 'auto' | true | false;
|
|
9
|
+
};
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
- **Default:** `undefined`
|
|
13
|
+
|
|
14
|
+
Adding an `integrity` attribute to `<script>` and `<link rel="stylesheet">` tags introduced by HTML allows the browser to verify the integrity of the introduced resource, thus preventing tampering with the downloaded resource.
|
|
15
|
+
|
|
16
|
+
:::info
|
|
17
|
+
For a specific introduction to SRI, you can refer to [Rsbuild security.sri](https://v2.rsbuild.rs/zh/config/security/sri).
|
|
18
|
+
|
|
19
|
+
This configuration type is not completely consistent with Rsbuild and will be automatically converted during the build process.
|
|
20
|
+
:::
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# server.baseUrl
|
|
2
|
+
|
|
3
|
+
- **Type:** `string | string[]`
|
|
4
|
+
- **Default:** `undefined`
|
|
5
|
+
|
|
6
|
+
Uniformly set the prefix of server-side routes (commonly used in situations where multiple applications share the same domain name to distinguish traffic).
|
|
7
|
+
|
|
8
|
+
```ts title="modern.config.ts"
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
server: {
|
|
11
|
+
// All generated routes will automatically have the prefix `/base`
|
|
12
|
+
// Generated server-side route file path: dist/route.json
|
|
13
|
+
baseUrl: '/base'
|
|
14
|
+
|
|
15
|
+
// Multiple baseUrl
|
|
16
|
+
baseUrl: ['/base-new', '/base-old']
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After running `dev`, you will see that the route access will have the corresponding prefix added:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
> Local: http://localhost:8080/base/
|
|
25
|
+
> Network: http://192.168.0.1:8080/base/
|
|
26
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# server.port
|
|
2
|
+
|
|
3
|
+
- **Type:** `number`
|
|
4
|
+
- **Default:** `8080`
|
|
5
|
+
|
|
6
|
+
When running the `dev` and `serve` commands, Modern.js will start with `8080` as the default port and automatically increase the port number when the port is occupied. You can use this configuration to modify the port number that the Server starts with:
|
|
7
|
+
|
|
8
|
+
```js title="modern.config.ts"
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
server: {
|
|
11
|
+
port: 3000,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
:::info
|
|
17
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - server.port](https://v2.rsbuild.dev/config/server/port).
|
|
18
|
+
:::
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# server.publicRoutes
|
|
2
|
+
|
|
3
|
+
- **Type:** `Object`
|
|
4
|
+
- **Default:** Server-side routing rules generated based on file conventions, with one route rule generated for each file.
|
|
5
|
+
|
|
6
|
+
This configuration option only applies to server-side routing and can customize the access route of resources under `config/public/`.
|
|
7
|
+
|
|
8
|
+
The `key` of the object is the relative file path of the `config/public/` (without using `./`), and the value can be a `string`.
|
|
9
|
+
|
|
10
|
+
```ts title="modern.config.ts"
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
server: {
|
|
13
|
+
publicRoutes: {
|
|
14
|
+
// Set a long route
|
|
15
|
+
'index.json': '/user-config/card-info/extra/help.json',
|
|
16
|
+
|
|
17
|
+
// Set a route without a suffix
|
|
18
|
+
'robot.txt': '/app/authentication',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# server.routes
|
|
2
|
+
|
|
3
|
+
- **Type:** `Object`
|
|
4
|
+
- **Default:** Server-side routing rules generated based on file conventions, with one route rule generated for each entry, and the entry name is equal to the route path.
|
|
5
|
+
|
|
6
|
+
This configuration option only applies to server-side routing and can customize the access route of application entries.
|
|
7
|
+
|
|
8
|
+
## Custom access routes
|
|
9
|
+
|
|
10
|
+
The `key` of the object is the name of the current application entry, and the value can be a `string | Array<string>`.
|
|
11
|
+
|
|
12
|
+
When the value type is `string`, the current value represents the route path for accessing the entry.
|
|
13
|
+
|
|
14
|
+
```ts title="modern.config.ts"
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
server: {
|
|
17
|
+
routes: {
|
|
18
|
+
// Default route is /entryName1, customized to /p/test1
|
|
19
|
+
entryName1: '/p/test1'
|
|
20
|
+
// Supports dynamic server-side routing configuration
|
|
21
|
+
entryName2: '/detail/:id'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Multiple access routes can also be set for the entry through `Array<string>`:
|
|
28
|
+
|
|
29
|
+
```ts title="modern.config.ts"
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
server: {
|
|
32
|
+
routes: {
|
|
33
|
+
'page-a': [`/a`, '/b'],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
At this time, the `page-a` entry can be accessed through both the `/a` and `/b` routes.
|
|
40
|
+
|
|
41
|
+
After executing the `dev` command, you can view two route records for the `page-a` entry in `dist/route.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"routes": [
|
|
46
|
+
{
|
|
47
|
+
"urlPath": "/a",
|
|
48
|
+
"entryName": "page-a",
|
|
49
|
+
"entryPath": "html/page-a/index.html",
|
|
50
|
+
"isSPA": true,
|
|
51
|
+
"isSSR": false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"urlPath": "/b",
|
|
55
|
+
"entryName": "page-a",
|
|
56
|
+
"entryPath": "html/page-a/index.html",
|
|
57
|
+
"isSPA": true,
|
|
58
|
+
"isSSR": false
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Custom response headers
|
|
65
|
+
|
|
66
|
+
Response headers can be set by configuring the `resHeaders` of the entry:
|
|
67
|
+
|
|
68
|
+
```ts title="modern.config.ts"
|
|
69
|
+
export default defineConfig({
|
|
70
|
+
server: {
|
|
71
|
+
routes: {
|
|
72
|
+
'page-a': {
|
|
73
|
+
route: ['/a', '/b'],
|
|
74
|
+
resHeaders: {
|
|
75
|
+
'x-modern-test': '1',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
:::note
|
|
84
|
+
This configuration takes effect in both the production and development environments, and different response headers can be set according to the NODE\_ENV to distinguish between environments. However, if you only need to set response headers in the development environment, it is recommended to use `tools.devServer.headers`.
|
|
85
|
+
|
|
86
|
+
:::
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# server.rsc
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean`
|
|
4
|
+
- **Default:** `false`
|
|
5
|
+
|
|
6
|
+
Enable React Server Components (RSC) configuration.
|
|
7
|
+
|
|
8
|
+
When set to `true`, enables React Server Components support in Modern.js. This allows components to be rendered on the server, providing better performance and developer experience.
|
|
9
|
+
|
|
10
|
+
```ts title="modern.config.ts"
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
server: {
|
|
13
|
+
rsc: true,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
:::tip Prerequisites
|
|
19
|
+
Before enabling RSC, ensure:
|
|
20
|
+
|
|
21
|
+
1. React and React DOM are upgraded to version 19 (recommended 19.2.4 or above)
|
|
22
|
+
2. Install the `react-server-dom-rspack@0.0.2` dependency
|
|
23
|
+
|
|
24
|
+
:::
|
|
25
|
+
|
|
26
|
+
For more information about using RSC, see the [React Server Components guide](/guides/basic-features/render/rsc.md).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# server.ssrByEntries
|
|
2
|
+
|
|
3
|
+
- **Type:** `Object`
|
|
4
|
+
- **Default:** `undefined`
|
|
5
|
+
|
|
6
|
+
Set SSR options by entry, and the properties inside the option are the same as [ssr](/configure/app/server/ssr.md). The specified value will be replaced and merged with the content of the SSR attribute, for example:
|
|
7
|
+
|
|
8
|
+
:::info
|
|
9
|
+
The "entry name" defaults to the directory name. In a few cases, when defining an entry through `source.entries`, the entry name is the `key` of the `source.entries` object.
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
```ts title="modern.config.ts"
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
server: {
|
|
16
|
+
ssr: true,
|
|
17
|
+
ssrByEntries: {
|
|
18
|
+
// page-a does not enable SSR
|
|
19
|
+
'page-a': false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
In the above configuration, the project enables SSR as a whole, but the SSR rendering ability is disabled for the `page-a` entry.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# server.ssr
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean`
|
|
4
|
+
- **Default:** `false`
|
|
5
|
+
|
|
6
|
+
Enalbe SSR configuration.
|
|
7
|
+
|
|
8
|
+
### Boolean Type
|
|
9
|
+
|
|
10
|
+
When the value type is `boolean`, it indicates whether to enable SSR deployment mode. The default is `false` to disable it.
|
|
11
|
+
|
|
12
|
+
```ts title="modern.config.ts"
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
server: {
|
|
15
|
+
ssr: true,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Object Type
|
|
21
|
+
|
|
22
|
+
When the value type is `Object`, the following properties can be configured:
|
|
23
|
+
|
|
24
|
+
| Name | Type | Default | Description |
|
|
25
|
+
| ----------------- | ------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
|
|
27
|
+
| forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
|
|
28
|
+
| unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR\_DATA. Developers can use this configuration to specify the headers that need to be injected |
|
|
29
|
+
| loaderFailureMode | `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/guides/basic-features/data/data-fetch.md#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes.md#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/guides/basic-features/data/data-fetch.md#client-loader) |
|
|
30
|
+
|
|
31
|
+
```ts title="modern.config.ts"
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
server: {
|
|
34
|
+
ssr: {
|
|
35
|
+
forceCSR: true,
|
|
36
|
+
mode: 'stream',
|
|
37
|
+
unsafeHeaders: ['User-Agent']
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Active Fallback
|
|
44
|
+
|
|
45
|
+
In a production environment, there are scenarios where it is necessary to actively fallback an SSR project to CSR. Examples include
|
|
46
|
+
|
|
47
|
+
1. When the SSR fails, a fallback to the CSR is required to ensure product availability.
|
|
48
|
+
|
|
49
|
+
2. When the SSR is working normally, but there are rendering failures during csr, debugging is required.
|
|
50
|
+
|
|
51
|
+
3. When the SSR server is under heavy load, it may be necessary to fallback some traffic directly to the CSR to avoid service downtime.
|
|
52
|
+
|
|
53
|
+
By configuring `server.ssr.forceCSR` to `true` in the project, you can control this behavior through query strings or request headers.
|
|
54
|
+
|
|
55
|
+
For example, in a custom Web Server middleware, you can actively fallback when traffic exceeds a certain threshold:
|
|
56
|
+
|
|
57
|
+
```ts title="server/modern.server.ts"
|
|
58
|
+
import {
|
|
59
|
+
defineServerConfig,
|
|
60
|
+
type MiddlewareHandler,
|
|
61
|
+
} from '@modern-js/server-runtime';
|
|
62
|
+
|
|
63
|
+
export const handler: MiddlewareHandler = async (c, next) => {
|
|
64
|
+
if (condition) {
|
|
65
|
+
c.set('forceCSR', '1');
|
|
66
|
+
}
|
|
67
|
+
await next();
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default defineServerConfig({
|
|
71
|
+
middlewares: [
|
|
72
|
+
{
|
|
73
|
+
name: 'request-middleware',
|
|
74
|
+
handler,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# server.tsconfigPath
|
|
2
|
+
|
|
3
|
+
- **Type:** `string`
|
|
4
|
+
- **Default:** `<appDirectory>/tsconfig.json`
|
|
5
|
+
|
|
6
|
+
Specifies the tsconfig file used by server-side TypeScript processes.
|
|
7
|
+
|
|
8
|
+
This option affects:
|
|
9
|
+
|
|
10
|
+
- BFF / API compilation (`@modern-js/plugin-bff`)
|
|
11
|
+
- Custom server compilation (`*.ts` files under `server/`)
|
|
12
|
+
- Runtime ts-node registration, such as SSR, `modern.config.ts`, and `.ts` files under `config/`
|
|
13
|
+
|
|
14
|
+
When this option is not set, `<appDirectory>/tsconfig.json` is used by default.
|
|
15
|
+
|
|
16
|
+
## When to use
|
|
17
|
+
|
|
18
|
+
Use this option when frontend and server-side code need different TypeScript configurations.
|
|
19
|
+
|
|
20
|
+
For example, the frontend can use `moduleResolution: "Bundler"`, while the server side uses `moduleResolution: "NodeNext"` for type resolution of conditional exports or subpath exports.
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
The example below uses `tsconfig.server.json` as the file name. You can use another name in your project.
|
|
25
|
+
|
|
26
|
+
Add `<appDirectory>/tsconfig.server.json`:
|
|
27
|
+
|
|
28
|
+
```jsonc title="tsconfig.server.json"
|
|
29
|
+
{
|
|
30
|
+
"extends": "./tsconfig.json",
|
|
31
|
+
"compilerOptions": {
|
|
32
|
+
"module": "NodeNext",
|
|
33
|
+
"moduleResolution": "NodeNext",
|
|
34
|
+
"target": "ES2022",
|
|
35
|
+
"lib": ["ESNext"],
|
|
36
|
+
"types": ["node"],
|
|
37
|
+
"esModuleInterop": true,
|
|
38
|
+
"experimentalDecorators": true,
|
|
39
|
+
"emitDecoratorMetadata": true
|
|
40
|
+
},
|
|
41
|
+
"include": ["api", "shared", "server", "config", "modern.config.ts"]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Specify this file in `modern.config.ts`:
|
|
46
|
+
|
|
47
|
+
```ts title="modern.config.ts"
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
server: {
|
|
50
|
+
tsconfigPath: './tsconfig.server.json',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Notes
|
|
56
|
+
|
|
57
|
+
- `tsconfigPath` is resolved relative to `appDirectory`. Absolute paths are also supported.
|
|
58
|
+
- It is recommended to inherit shared options such as `paths` from the root tsconfig through `extends`, instead of maintaining them in multiple files.
|
|
59
|
+
- If the configured file does not exist, TypeScript / ts-node will throw an error at startup.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# source.aliasStrategy
|
|
2
|
+
|
|
3
|
+
:::warning Deprecation Warning
|
|
4
|
+
`source.aliasStrategy` is deprecated, please use [resolve.aliasStrategy](/configure/app/resolve/alias-strategy.md) instead.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
- **Type:** `'prefer-tsconfig' | 'prefer-alias'`
|
|
8
|
+
- **Default:** `'prefer-tsconfig'`
|
|
9
|
+
|
|
10
|
+
`source.aliasStrategy` is used to control the priority between the `paths` option in `tsconfig.json` and the `alias` option in the bundler.
|
|
11
|
+
|
|
12
|
+
:::info
|
|
13
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.aliasStrategy](https://v2.rsbuild.dev/config/source/alias-strategy).
|
|
14
|
+
:::
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# source.alias
|
|
2
|
+
|
|
3
|
+
:::warning Deprecation Warning
|
|
4
|
+
`source.alias` is deprecated, please use [resolve.alias](/configure/app/resolve/alias.md) instead.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
- **Type:**
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
type Alias = Record<string, string | false | (string | false)[]> | Function;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- **Default:** `undefined`
|
|
14
|
+
|
|
15
|
+
Create aliases to import or require certain modules, same as the [resolve.alias](https://rspack.rs/config/resolve#resolvealias) config of Rspack.
|
|
16
|
+
|
|
17
|
+
:::tip
|
|
18
|
+
For TypeScript projects, you only need to configure [compilerOptions.paths](https://www.typescriptlang.org/tsconfig#paths) in the `tsconfig.json` file. The Rsbuild will automatically recognize it, so there is no need to configure the `source.alias` option separately. For more details, please refer to [Path Aliases](https://modernjs.dev/en/guides/basic-features/alias.html).
|
|
19
|
+
:::
|
|
20
|
+
|
|
21
|
+
:::info
|
|
22
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.alias](https://v2.rsbuild.dev/config/source/alias).
|
|
23
|
+
:::
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# source.configDir
|
|
2
|
+
|
|
3
|
+
- **Type:** `string`
|
|
4
|
+
- **Default:** `'./config'`
|
|
5
|
+
|
|
6
|
+
Modern.js supports placing some files in the `./config` folder to customize HTML templates, icons, static assets, etc. For details, please refer to [File Convention](/apis/app/hooks/config/html.md).
|
|
7
|
+
|
|
8
|
+
This option allows you to customize the directory of the configuration files.
|
|
9
|
+
|
|
10
|
+
For example, adjust the assets directory to the `resources` directory:
|
|
11
|
+
|
|
12
|
+
```js title="modern.config.ts"
|
|
13
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
source: {
|
|
17
|
+
configDir: './resources',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
```
|