@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,25 @@
|
|
|
1
|
+
# source.decorators
|
|
2
|
+
|
|
3
|
+
- **Type:**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type Decorators = {
|
|
7
|
+
version?: 'legacy' | '2022-03';
|
|
8
|
+
};
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **Default:**
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const defaultDecorators = {
|
|
15
|
+
version: 'legacy';
|
|
16
|
+
};
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Used to configure the decorators syntax.
|
|
20
|
+
|
|
21
|
+
:::warning
|
|
22
|
+
The usage of this configuration item is exactly the same as that of Rsbuild, but the default value is different. For detailed information, please refer to [Rsbuild - source.decorators](https://v2.rsbuild.rs/config/source/decorators).
|
|
23
|
+
:::
|
|
24
|
+
|
|
25
|
+
We found that most projects still use the `legacy` version of the decorator syntax, so the default value is `legacy`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# source.define
|
|
2
|
+
|
|
3
|
+
- **Type:** `Record<string, unknown>`
|
|
4
|
+
- **Default:**
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const defaultDefine = {
|
|
8
|
+
'process.env.MODERN_TARGET': '"browser"',
|
|
9
|
+
};
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior between development builds and production builds.
|
|
13
|
+
|
|
14
|
+
:::info
|
|
15
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.define](https://v2.rsbuild.dev/config/source/define).
|
|
16
|
+
:::
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# source.disableDefaultEntries
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean`
|
|
4
|
+
- **Default:** `false`
|
|
5
|
+
|
|
6
|
+
Used to disable the functionality of automatically identifying page entry points based on directory structure.
|
|
7
|
+
|
|
8
|
+
:::info
|
|
9
|
+
By default, Modern.js automatically determines the entry points of pages based on directory conventions, as described in [Entries](/guides/concept/entries.md).
|
|
10
|
+
|
|
11
|
+
:::
|
|
12
|
+
|
|
13
|
+
To disable this default behavior, set the following:
|
|
14
|
+
|
|
15
|
+
```ts title="modern.config.ts"
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
source: {
|
|
18
|
+
disableDefaultEntries: true,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
After disabling the default behavior, you will need to use the [`source.entries`](/configure/app/source/entries.md) configuration to define custom entry points.
|
|
24
|
+
|
|
25
|
+
:::warning
|
|
26
|
+
We recommend organizing your code using the directory conventions provided by Modern.js to make better use of the framework's functionality and to avoid some redundant configurations.
|
|
27
|
+
|
|
28
|
+
:::
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# source.enableAsyncEntry
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean`
|
|
4
|
+
- **Default:** `false`
|
|
5
|
+
|
|
6
|
+
This option is used for Rspack Module Federation scenario.
|
|
7
|
+
|
|
8
|
+
When this option is enabled, Modern.js will wrap the automatically generated entry files with dynamic import (Asynchronous Boundaries), allowing page code to consume remote modules generated by Module Federation.
|
|
9
|
+
|
|
10
|
+
## Background
|
|
11
|
+
|
|
12
|
+
Module Federation (MF) is a technology solution that allows multiple JavaScript applications to share code and resources. Similar to microservices architecture on the server side, it allows you to split large applications into multiple independent smaller applications that can be developed, tested, and deployed independently, while dynamically loading modules from other applications at runtime.
|
|
13
|
+
|
|
14
|
+
Module Federation solves the problem of code duplication across multiple frontend applications. In the traditional approach, if multiple applications need to use the same components or utility functions, you would need to duplicate this code in each application, leading to code duplication, high maintenance costs, and larger application sizes. With Module Federation, you can place common code in one application and have other applications load it dynamically as needed, enabling code sharing and reducing duplication.
|
|
15
|
+
|
|
16
|
+
Module Federation 2.0 supports [Rspack](https://rspack.rs/) build tools, and provides enhanced features such as dynamic type hints, Manifest, Federation Runtime, runtime plugin system, and Chrome Devtools support for better development experience and debugging capabilities. You can visit the [Module Federation official documentation](https://module-federation.io/) to learn more.
|
|
17
|
+
|
|
18
|
+
Modern.js provides an example project for Module Federation. Please refer to [module-federation-examples - modernjs](https://github.com/module-federation/module-federation-examples/tree/db5bdbeee56f779999a2c591fc553eb94eb20b36/modernjs).
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
First, enable this option in the configuration file:
|
|
23
|
+
|
|
24
|
+
```ts title="modern.config.ts"
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
source: {
|
|
27
|
+
enableAsyncEntry: true,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then run the `dev` or `build` command, and you will see that the files automatically generated by Modern.js have the following structure:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
node_modules
|
|
36
|
+
└─ .modern-js
|
|
37
|
+
└─ main
|
|
38
|
+
├─ bootstrap.jsx # asynchronous entry file
|
|
39
|
+
├─ index.js # real entry code
|
|
40
|
+
└─ index.html
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The contents of `bootstrap.js` are as follows:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import('./index.jsx');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
At this point, you can consume any remote module in the current page.
|
|
50
|
+
|
|
51
|
+
:::info
|
|
52
|
+
Modern.js does not have ModuleFederationPlugin plugin built in. Please configure the ModuleFederationPlugin yourself via [tools.bundlerChain](/configure/app/tools/bundler-chain.md).
|
|
53
|
+
|
|
54
|
+
:::
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# source.enableAsyncPreEntry
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean`
|
|
4
|
+
- **Default:** `false`
|
|
5
|
+
|
|
6
|
+
When enabled, Modern.js will inject the modules configured in `source.preEntry` to the top of the auto-generated entry file (`index.jsx`) in order.
|
|
7
|
+
|
|
8
|
+
This option only takes effect when `source.enableAsyncEntry` is enabled. If async entry is not enabled, this behavior will be skipped and the original builder-side `source.preEntry` injection remains unchanged.
|
|
9
|
+
|
|
10
|
+
This option is mainly designed to work with `source.enableAsyncEntry`: when async entry is enabled, the final build entry becomes `bootstrap.jsx`, and the builder-side `source.preEntry` may not be injected into the real entry code. With `source.enableAsyncPreEntry` enabled, `preEntry` will be injected into `index.jsx` (the real entry code), so it also works in async entry scenarios.
|
|
11
|
+
|
|
12
|
+
Meanwhile, when both `source.enableAsyncEntry` and `source.enableAsyncPreEntry` are enabled, Modern.js will not pass `source.preEntry` into builder config to avoid duplicate injection or injection into an unexpected entry.
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
```ts title="modern.config.ts"
|
|
17
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
source: {
|
|
21
|
+
enableAsyncEntry: true,
|
|
22
|
+
enableAsyncPreEntry: true,
|
|
23
|
+
preEntry: ['./src/pre-a.ts', './src/pre-b.ts'],
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# source.entriesDir
|
|
2
|
+
|
|
3
|
+
- **Type:** `string`
|
|
4
|
+
- **Default:** `'./src'`
|
|
5
|
+
|
|
6
|
+
By default, Modern.js scans the `src` directory to identify page entries. You can customize the directory used for identifying page entries with this option.
|
|
7
|
+
|
|
8
|
+
For example, with the following configuration and directory structure:
|
|
9
|
+
|
|
10
|
+
```ts title="modern.config.ts"
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
source: {
|
|
13
|
+
entriesDir: './src/pages',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash title="Project directory structure"
|
|
19
|
+
.
|
|
20
|
+
└── src
|
|
21
|
+
└── pages
|
|
22
|
+
├── a
|
|
23
|
+
│ └── App.tsx
|
|
24
|
+
└── b
|
|
25
|
+
└── App.tsx
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Modern.js will generate the build entries `a` and `b` based on the `./src/pages` directory structure. The result is as follows:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const entry = {
|
|
32
|
+
a: './src/pages/a/App.tsx',
|
|
33
|
+
b: './src/pages/b/App.tsx',
|
|
34
|
+
};
|
|
35
|
+
```
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# source.entries
|
|
2
|
+
|
|
3
|
+
- **Type:**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type Entries = Record<
|
|
7
|
+
string,
|
|
8
|
+
| string
|
|
9
|
+
| {
|
|
10
|
+
entry: string;
|
|
11
|
+
disableMount?: boolean;
|
|
12
|
+
}
|
|
13
|
+
>;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- **Default:** The entry object calculated based on the directory structure of the current project.
|
|
17
|
+
|
|
18
|
+
Used to configure custom page entries.
|
|
19
|
+
|
|
20
|
+
:::tip When to use
|
|
21
|
+
For most scenarios, the entry automatically generated by Modern.js based on the directory structure can meet the requirements. For details, please refer to [Entry](/guides/concept/entries.md).
|
|
22
|
+
|
|
23
|
+
If you need to customize page entries, you can set them through this option.
|
|
24
|
+
|
|
25
|
+
:::
|
|
26
|
+
|
|
27
|
+
## String
|
|
28
|
+
|
|
29
|
+
When the value of the `entries` object is of type `string`, it represents the file path of the entry module:
|
|
30
|
+
|
|
31
|
+
```ts title="modern.config.ts"
|
|
32
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
source: {
|
|
36
|
+
entries: {
|
|
37
|
+
// Specify a new entry named 'my-entry'
|
|
38
|
+
'my-entry': './src/home/test/index.ts',
|
|
39
|
+
},
|
|
40
|
+
disableDefaultEntries: true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
By default, the configured entry is equivalent to `App.tsx`, which means that the specified entry file **only needs to export the root component of the application**.
|
|
46
|
+
|
|
47
|
+
For example, the following directory structure:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
.
|
|
51
|
+
├── src
|
|
52
|
+
│ └── entry
|
|
53
|
+
│ ├── chat.tsx
|
|
54
|
+
│ └── home.tsx
|
|
55
|
+
└── package.json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The above directory does not conform to the directory structure convention of Modern.js, so Modern.js will not get any default entries when analyzing the directory structure.
|
|
59
|
+
|
|
60
|
+
If you do not want to change the directory structure (such as project migration), you can customize the entry through `source.entries`:
|
|
61
|
+
|
|
62
|
+
```ts title="modern.config.ts"
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
source: {
|
|
65
|
+
entries: {
|
|
66
|
+
home: './src/entry/home.tsx',
|
|
67
|
+
chat: './src/entry/chat.tsx',
|
|
68
|
+
},
|
|
69
|
+
disableDefaultEntries: true,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Object
|
|
75
|
+
|
|
76
|
+
When the value is `Object`, the following attributes can be configured:
|
|
77
|
+
|
|
78
|
+
- `entry`: `string`, the entry file path.
|
|
79
|
+
- `disableMount`: `boolean = false`, disable Modern.js's behavior of automatically generating entry code.
|
|
80
|
+
|
|
81
|
+
```ts title="modern.config.ts"
|
|
82
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
83
|
+
|
|
84
|
+
export default defineConfig({
|
|
85
|
+
source: {
|
|
86
|
+
entries: {
|
|
87
|
+
'my-entry': {
|
|
88
|
+
// entry file path
|
|
89
|
+
entry: './src/my-page/index.tsx',
|
|
90
|
+
disableMount: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
// Disable default entry scanning
|
|
94
|
+
disableDefaultEntries: true,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Disable entry file generation
|
|
100
|
+
|
|
101
|
+
By default, the configured entry is equivalent to `App.tsx`, and Modern.js will automatically generate an entry file to reference the entry you configured.
|
|
102
|
+
|
|
103
|
+
If you want to disable the logic of Modern.js automatically generating entry files, you can set the `disableMount` property to `true`.
|
|
104
|
+
|
|
105
|
+
```ts title="modern.config.ts"
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
source: {
|
|
108
|
+
entries: {
|
|
109
|
+
'my-entry': {
|
|
110
|
+
entry: './src/my-page/index.tsx',
|
|
111
|
+
disableMount: true,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
// Disable default entry scanning
|
|
115
|
+
disableDefaultEntries: true,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Conventional Routing
|
|
121
|
+
|
|
122
|
+
If you need to enable conventional routing for a custom entry, you can set `entry` to a directory path:
|
|
123
|
+
|
|
124
|
+
```ts title="modern.config.ts"
|
|
125
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
126
|
+
|
|
127
|
+
export default defineConfig({
|
|
128
|
+
source: {
|
|
129
|
+
entries: {
|
|
130
|
+
// enable conventional routing
|
|
131
|
+
entry_spa: {
|
|
132
|
+
// The entry path of conventional routing must be set to a directory
|
|
133
|
+
entry: './src/about',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
// Disable default entry scanning
|
|
137
|
+
disableDefaultEntries: true,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Entry Merge Rules
|
|
143
|
+
|
|
144
|
+
After setting `source.entries`, if `disableDefaultEntries: true` is not set, Modern.js will merge the custom entry with the entry obtained by analyzing the directory structure.
|
|
145
|
+
|
|
146
|
+
The merge rule is:
|
|
147
|
+
|
|
148
|
+
- Compare the entry paths set by the custom entry setting and the default entry path. When the entry paths are the same, the custom entry will override the default entry.
|
|
149
|
+
|
|
150
|
+
For example, the following directory structure:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
.
|
|
154
|
+
├── src
|
|
155
|
+
│ ├── chat
|
|
156
|
+
│ │ └── App.tsx
|
|
157
|
+
│ └── home
|
|
158
|
+
│ └── index.ts
|
|
159
|
+
└── package.json
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Modern.js will analyze the `src/` directory and get the default entries `chat` and `home`. When the user configures as follows in the `modern.config.ts` file:
|
|
163
|
+
|
|
164
|
+
```ts title="modern.config.ts"
|
|
165
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
166
|
+
|
|
167
|
+
export default defineConfig({
|
|
168
|
+
source: {
|
|
169
|
+
entries: {
|
|
170
|
+
index: './src/home/index.ts',
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
It can be seen that the path of the custom entry `index` is the same as the path of the default entry `home`. During the merge process, `index` will override `home`, and the final entry is as follows:
|
|
177
|
+
|
|
178
|
+
- `chat -> ./src/chat/App.tsx`
|
|
179
|
+
- `index -> ./src/home/index.ts`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# source.exclude
|
|
2
|
+
|
|
3
|
+
- **Type:** [RuleSetCondition\[\]](https://rspack.rs/config/module#condition)
|
|
4
|
+
- **Default:** `[]`
|
|
5
|
+
|
|
6
|
+
Specifies JavaScript/TypeScript files that do not need to be compiled. The usage is consistent with [Rule.exclude](https://rspack.rs/config/module#ruleexclude) in Rspack, which supports passing in strings or regular expressions to match the module path.
|
|
7
|
+
|
|
8
|
+
:::info
|
|
9
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.exclude](https://v2.rsbuild.dev/config/source/exclude).
|
|
10
|
+
:::
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# source.globalVars
|
|
2
|
+
|
|
3
|
+
- **Type:** `Record<string, JSONValue> | Function`
|
|
4
|
+
- **Default:**
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const defaultGlobalVars = {
|
|
8
|
+
// The environment variable `process.env.NODE_ENV` will be added by default,
|
|
9
|
+
// so you don't need to set it in manually.
|
|
10
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
11
|
+
};
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Used to define global variables. It can replace expressions like `process.env.FOO` in your code after compile. Such as:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
console.log(process.env.NODE_ENV);
|
|
18
|
+
|
|
19
|
+
// ⬇️ Turn into being...
|
|
20
|
+
console.log('development');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Example
|
|
24
|
+
|
|
25
|
+
In the following example, the `ENABLE_VCONSOLE` and `APP_CONTEXT` are injected into the code:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
export default {
|
|
29
|
+
source: {
|
|
30
|
+
globalVars: {
|
|
31
|
+
ENABLE_VCONSOLE: true,
|
|
32
|
+
APP_CONTEXT: { answer: 42 },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
You can use them directly in your code:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
if (ENABLE_VCONSOLE) {
|
|
42
|
+
// do something
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(APP_CONTEXT);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Function Usage
|
|
49
|
+
|
|
50
|
+
- **Type:**
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
type GlobalVarsFn = (
|
|
54
|
+
obj: Record<string, JSONValue>,
|
|
55
|
+
utils: { env: NodeEnv; target: BuilderTarget },
|
|
56
|
+
) => Record<string, JSONValue> | void;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can set `source.globalVars` to a function to dynamically setting some environment variables.
|
|
60
|
+
|
|
61
|
+
For example, dynamically set according to the build target:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
export default {
|
|
65
|
+
source: {
|
|
66
|
+
globalVars(obj, { target }) {
|
|
67
|
+
obj['MY_TARGET'] = target === 'node' ? 'server' : 'client';
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Difference with define
|
|
74
|
+
|
|
75
|
+
You can take `source.globalVars` as the syntax sugar of `source.define`, the only difference is that `source.globalVars` will automatically stringify the value, which makes it easier to set the value of global variables. The values of `globalVars` should be JSON-safe to ensure it can be serialized.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
export default {
|
|
79
|
+
source: {
|
|
80
|
+
globalVars: {
|
|
81
|
+
'process.env.BUILD_VERSION': '0.0.1',
|
|
82
|
+
'import.meta.foo': { bar: 42 },
|
|
83
|
+
'import.meta.baz': false,
|
|
84
|
+
},
|
|
85
|
+
define: {
|
|
86
|
+
'process.env.BUILD_VERSION': JSON.stringify('0.0.1'),
|
|
87
|
+
'import.meta': {
|
|
88
|
+
foo: JSON.stringify({ bar: 42 }),
|
|
89
|
+
baz: JSON.stringify(false),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Precautions
|
|
97
|
+
|
|
98
|
+
`source.globalVars` injects environment variables through string replacement, so it cannot take effect on dynamic syntaxes such as destructuring.
|
|
99
|
+
|
|
100
|
+
When using destructuring assignment, Modern.js will not be able to determine whether the variable `NODE_ENV` is associated with the expression `process.env.NODE_ENV` to be replaced, so the following usage is invalid:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
const { NODE_ENV } = process.env;
|
|
104
|
+
console.log(NODE_ENV);
|
|
105
|
+
// ❌ Won't get a string.
|
|
106
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# source.include
|
|
2
|
+
|
|
3
|
+
- **Type:** [RuleSetCondition\[\]](https://rspack.rs/config/module#condition)
|
|
4
|
+
- **Default value:**
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
const defaultInclude = [
|
|
8
|
+
[{ not: /[\\/]node_modules[\\/]/ }, /\.(?:ts|tsx|jsx|mts|cts)$/],
|
|
9
|
+
];
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`source.include` is used to specify additional JavaScript files that need to be compiled. By default, the following files will be compiled:
|
|
13
|
+
|
|
14
|
+
- TypeScript and JSX files in any directory, with file extensions matching `.ts`, `.tsx`, `.jsx`, `.mts`, `.cts`.
|
|
15
|
+
- JavaScript files not in the `node_modules` directory, with file extensions matching `.js`, `.mjs`, `.cjs`.
|
|
16
|
+
|
|
17
|
+
:::tip
|
|
18
|
+
Before Rsbuild version 1.4, the default value of `source.include` was:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const defaultInclude = [
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
and: [APP_ROOT, { not: /[\\/]node_modules[\\/]/ }],
|
|
25
|
+
},
|
|
26
|
+
/\.(?:ts|tsx|jsx|mts|cts)$/,
|
|
27
|
+
],
|
|
28
|
+
];
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The difference from the new version is that `.js`, `.mjs`, `.cjs` files only in the current directory will be compiled.
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
:::info
|
|
35
|
+
该配置项的使用方式与 Rsbuild 完全一致。详细信息请参考 [Rsbuild - source.include](https://v2.rsbuild.dev/config/source/include)。
|
|
36
|
+
:::
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# source.mainEntryName
|
|
2
|
+
|
|
3
|
+
- **Type:** `string`
|
|
4
|
+
- **Default:** `'index'`
|
|
5
|
+
|
|
6
|
+
This option is used to configure the main entry name of Modern.js.
|
|
7
|
+
|
|
8
|
+
By default, the default main entry name of Modern.js is `index`. When using a single entry or the entry name is the same as the `name` field in `package.json`, the corresponding entry will be used as the main entry. This configuration can be used to modify the name of the main entry.
|
|
9
|
+
|
|
10
|
+
For example, change the main entry name to main:
|
|
11
|
+
|
|
12
|
+
```ts title="modern.config.ts"
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
source: {
|
|
15
|
+
mainEntryName: 'main',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
After building, the corresponding HTML output path will be changed to `dist/html/index/index.html`.
|
|
21
|
+
|
|
22
|
+
:::info
|
|
23
|
+
When the main entry name is modified, other `**ByEntries` configurations also need to be adjusted to use the modified entry name.
|
|
24
|
+
:::
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# source.preEntry
|
|
2
|
+
|
|
3
|
+
- **Type:** `string | string[]`
|
|
4
|
+
- **Default:** `[]`
|
|
5
|
+
|
|
6
|
+
Add a script before the entry file of each page. This script will be executed before the page code. It can be used to execute global logics, such as injecting polyfills, setting global styles, etc.
|
|
7
|
+
|
|
8
|
+
:::info
|
|
9
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.preEntry](https://v2.rsbuild.dev/config/source/pre-entry).
|
|
10
|
+
:::
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# source.reactCompiler
|
|
2
|
+
|
|
3
|
+
- **Type:** `boolean | ReactCompilerOptions`
|
|
4
|
+
- **Default:** `undefined` (disabled)
|
|
5
|
+
|
|
6
|
+
Whether to enable [React Compiler](https://react.dev/learn/react-compiler). React Compiler is a build-time tool that optimizes re-rendering performance of React applications through automatic memoization.
|
|
7
|
+
|
|
8
|
+
Modern.js implements this capability based on the Rust-based React Compiler built into Rspack's `builtin:swc-loader` (equivalent to setting SWC's `jsc.transform.reactCompiler`), reusing Rspack's built-in SWC transform chain without introducing Babel.
|
|
9
|
+
|
|
10
|
+
:::tip
|
|
11
|
+
This option is disabled by default. It must be enabled explicitly for any React version, including React 19.
|
|
12
|
+
:::
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
### Enable React Compiler (React 19)
|
|
17
|
+
|
|
18
|
+
```ts title="modern.config.ts"
|
|
19
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
source: {
|
|
23
|
+
reactCompiler: true,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Using with React 18
|
|
29
|
+
|
|
30
|
+
The compiled output targets React 19 by default. To use it in React 18 projects, you need to:
|
|
31
|
+
|
|
32
|
+
1. Install [react-compiler-runtime](https://www.npmjs.com/package/react-compiler-runtime) as a **runtime dependency** (the compiled output references it at runtime):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm add react-compiler-runtime
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Specify the React version via `target`:
|
|
39
|
+
|
|
40
|
+
```ts title="modern.config.ts"
|
|
41
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
source: {
|
|
45
|
+
reactCompiler: {
|
|
46
|
+
target: '18',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Customize compilation behavior
|
|
53
|
+
|
|
54
|
+
When passing an object, the options are the same as Rspack's `jsc.transform.reactCompiler`. For example, use `compilationMode: 'annotation'` to only compile functions annotated with the `"use memo"` directive:
|
|
55
|
+
|
|
56
|
+
```ts title="modern.config.ts"
|
|
57
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
58
|
+
|
|
59
|
+
export default defineConfig({
|
|
60
|
+
source: {
|
|
61
|
+
reactCompiler: {
|
|
62
|
+
compilationMode: 'annotation',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
For the complete list of options, see [Rsbuild - reactCompiler](https://rsbuild.rs/plugins/list/plugin-react#reactcompiler) and the [React Compiler configuration docs](https://react.dev/reference/react-compiler/configuration).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# source.transformImport
|
|
2
|
+
|
|
3
|
+
Transform the import path, which can be used to modularly import the subpath of third-party packages. The functionality is similar to [babel-plugin-import](https://www.npmjs.com/package/babel-plugin-import)。
|
|
4
|
+
|
|
5
|
+
- **Type:**
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
type TransformImport =
|
|
9
|
+
| false
|
|
10
|
+
| Array<{
|
|
11
|
+
libraryName: string;
|
|
12
|
+
libraryDirectory?: string;
|
|
13
|
+
style?: string | boolean;
|
|
14
|
+
styleLibraryDirectory?: string;
|
|
15
|
+
camelToDashComponentName?: boolean;
|
|
16
|
+
transformToDefaultImport?: boolean;
|
|
17
|
+
customName?: string;
|
|
18
|
+
customStyleName?: string;
|
|
19
|
+
}>
|
|
20
|
+
| Function;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- **Default:** `undefined`
|
|
24
|
+
|
|
25
|
+
:::info
|
|
26
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - source.transformImport](https://v2.rsbuild.dev/config/source/transform-import).
|
|
27
|
+
:::
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# splitChunks
|
|
2
|
+
|
|
3
|
+
- **Type:**
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
type SplitChunksConfig =
|
|
7
|
+
| (Rspack.OptimizationSplitChunksOptions & {
|
|
8
|
+
preset?: SplitChunksPreset;
|
|
9
|
+
})
|
|
10
|
+
| false;
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`splitChunks` is used to configure Rsbuild's chunk splitting strategy.
|
|
14
|
+
|
|
15
|
+
:::info
|
|
16
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to [Rsbuild - splitChunks](https://v2.rsbuild.dev/config/split-chunks).
|
|
17
|
+
:::
|