@modern-js/main-doc 2.25.1 → 2.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +14 -0
- package/docs/en/apis/app/commands.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +1 -1
- package/docs/en/components/custom-router-micro-frontend.mdx +40 -0
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +1 -1
- package/docs/en/configure/app/auto-load-plugin.mdx +1 -1
- package/docs/en/configure/app/bff/proxy.mdx +2 -2
- package/docs/en/configure/app/builder-plugins.mdx +1 -1
- package/docs/en/configure/app/runtime/master-app.mdx +1 -1
- package/docs/en/configure/app/runtime/state.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +6 -5
- package/docs/en/configure/app/tools/swc.mdx +2 -0
- package/docs/en/guides/advanced-features/bff/index.mdx +1 -0
- package/docs/en/guides/advanced-features/code-split.mdx +1 -1
- package/docs/en/guides/advanced-features/rspack-start.mdx +1 -1
- package/docs/en/guides/advanced-features/ssr.mdx +1 -1
- package/docs/en/guides/basic-features/data-fetch.mdx +1 -1
- package/docs/en/guides/get-started/quick-start.mdx +23 -3
- package/docs/en/guides/topic-detail/changesets/add.mdx +1 -1
- package/docs/en/guides/topic-detail/changesets/release-pre.mdx +1 -1
- package/docs/en/guides/topic-detail/changesets/release.mdx +1 -1
- package/docs/en/guides/topic-detail/framework-plugin/hook-list.mdx +67 -23
- package/docs/en/guides/topic-detail/generator/create/option.md +3 -3
- package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +1 -1
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +2 -2
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +3 -3
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/docs/en/guides/topic-detail/model/performance.mdx +1 -1
- package/docs/en/guides/topic-detail/model/quick-start.mdx +2 -2
- package/docs/en/guides/topic-detail/model/use-model.mdx +3 -3
- package/docs/zh/apis/monorepo/commands/deploy.mdx +1 -1
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/configure/app/deploy/microFrontend.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -5
- package/docs/zh/configure/app/tools/swc.mdx +2 -0
- package/docs/zh/guides/advanced-features/using-storybook.mdx +1 -1
- package/docs/zh/guides/get-started/quick-start.mdx +28 -7
- package/docs/zh/guides/topic-detail/framework-plugin/hook-list.mdx +67 -23
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +1 -1
- package/docs/zh/guides/topic-detail/model/performance.mdx +1 -1
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +1 -1
- package/docs/zh/guides/topic-detail/model/use-model.mdx +3 -3
- package/package.json +5 -5
- package/docs/zh/apis/monorepo/commands/_category_.json +0 -8
- package/docs/zh/apis/monorepo/commands/bump.mdx +0 -39
- package/docs/zh/apis/monorepo/commands/change.mdx +0 -57
- package/docs/zh/apis/monorepo/commands/clear.mdx +0 -24
- package/docs/zh/apis/monorepo/commands/gen-release-note.mdx +0 -32
- package/docs/zh/apis/monorepo/commands/index.mdx +0 -7
- package/docs/zh/apis/monorepo/commands/lint.mdx +0 -18
- package/docs/zh/apis/monorepo/commands/new.mdx +0 -39
- package/docs/zh/apis/monorepo/commands/pre.mdx +0 -65
- package/docs/zh/apis/monorepo/commands/release.mdx +0 -16
- package/docs/zh/apis/monorepo/commands/upgrade.mdx +0 -20
- package/docs/zh/apis/monorepo/hooks/_category_.json +0 -8
- package/docs/zh/apis/monorepo/hooks/apps.mdx +0 -14
- package/docs/zh/apis/monorepo/hooks/code-workspace.mdx +0 -11
- package/docs/zh/apis/monorepo/hooks/examples.mdx +0 -16
- package/docs/zh/apis/monorepo/hooks/features.mdx +0 -16
- package/docs/zh/apis/monorepo/hooks/index.mdx +0 -7
- package/docs/zh/apis/monorepo/hooks/packages.mdx +0 -16
- package/docs/zh/apis/monorepo/hooks/pnpm-workspace.mdx +0 -11
- package/docs/zh/apis/monorepo/hooks/pnpmfile.mdx +0 -11
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
+
## 2.26.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/builder-doc@2.26.0
|
8
|
+
|
9
|
+
## 2.25.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 4a83fcd: docs(main-doc): fix wrong links and add missing files
|
14
|
+
docs(main-doc): 修复错误的链接,补充缺失的文件
|
15
|
+
- @modern-js/builder-doc@2.25.2
|
16
|
+
|
3
17
|
## 2.25.1
|
4
18
|
|
5
19
|
### Patch Changes
|
@@ -71,7 +71,7 @@ modern dev --entry foo,bar
|
|
71
71
|
|
72
72
|
## modern build
|
73
73
|
|
74
|
-
The `modern build` command will build
|
74
|
+
The `modern build` command will build production-ready artifacts in the `dist/` directory by default. You can specify the output directory by modifying the configuration [`output.distPath`](/configure/app/output/dist-path).
|
75
75
|
|
76
76
|
```bash
|
77
77
|
Usage: modern build [options]
|
@@ -96,7 +96,7 @@ File sizes after production build:
|
|
96
96
|
645 B dist/static/css/main.0dd3ecc1.css
|
97
97
|
```
|
98
98
|
|
99
|
-
Open the above HTML file in the browser, you can see the tile diagram of the
|
99
|
+
Open the above HTML file in the browser, you can see the tile diagram of the bundled files, and perform package volume analysis and optimization:
|
100
100
|
|
101
101
|
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/mwa-build-analyze-8784f762c1ab0cb20935829d5f912c4c.png" />
|
102
102
|
|
@@ -7,7 +7,7 @@ sidebar_position: 2
|
|
7
7
|
|
8
8
|
## Favicon
|
9
9
|
|
10
|
-
When there is a `favicon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.favicon](/configure/app/html/favicon) configuration
|
10
|
+
When there is a `favicon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.favicon](/configure/app/html/favicon) configuration option for generating the favicon icon on the page:
|
11
11
|
|
12
12
|
```
|
13
13
|
./config
|
@@ -32,7 +32,7 @@ When setting up the favicon, Modern.js looks for files in the following order:
|
|
32
32
|
|
33
33
|
## Apple Touch Icon
|
34
34
|
|
35
|
-
When there is an `icon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.appIcon](/configure/app/html/app-icon) configuration
|
35
|
+
When there is an `icon.*` file in the `config` directory at the root of the project, Modern.js will automatically set the file to the [html.appIcon](/configure/app/html/app-icon) configuration option for generating the Apple Touch Icon icon under the iOS system.
|
36
36
|
|
37
37
|
```
|
38
38
|
./config
|
@@ -123,7 +123,7 @@ export const middleware: SomeType = (ctx, next) => {
|
|
123
123
|
};
|
124
124
|
```
|
125
125
|
|
126
|
-
By default, the framework extension capability of Web Server is turned off after installing the framework extension
|
126
|
+
By default, the framework extension capability of Web Server is turned off after installing the framework extension plugin. If you want to use the framework extension, you can turn it on through ['server.enableFrameworkExt'](/configure/app/server/enable-framework-ext.html).
|
127
127
|
|
128
128
|
|
129
129
|
:::info
|
@@ -0,0 +1,40 @@
|
|
1
|
+
```js title="src/App.tsx"
|
2
|
+
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
3
|
+
|
4
|
+
import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements, BrowserRouter, Link, Outlet } from '@modern-js/runtime/router';
|
5
|
+
|
6
|
+
const AppLayout = () => (
|
7
|
+
<>
|
8
|
+
<div><Link to={'/table'}>Loading conventional routed sub-applications</Link></div>
|
9
|
+
<div><Link to={'/dashboard'}>Loading Self-Controlled Routing Sub-Applications</Link></div>
|
10
|
+
<div><Link to={'/'}>Uninstall a sub-application</Link></div>
|
11
|
+
<Outlet />
|
12
|
+
</>
|
13
|
+
)
|
14
|
+
|
15
|
+
export default () => {
|
16
|
+
const { apps, MApp, Table, Dashboard } = useModuleApps();
|
17
|
+
|
18
|
+
// If you are not using the MApp component, you need to use createBrowserRouter to create the route.
|
19
|
+
const router = createBrowserRouter(
|
20
|
+
createRoutesFromElements(
|
21
|
+
<Route path="/" element={<AppLayout />}>
|
22
|
+
<Route key={'table'} path={'table/*'} element={<Table />} />
|
23
|
+
<Route key={'dashboard'} path={'dashboard/*'} element={<Dashboard />} />
|
24
|
+
</Route>
|
25
|
+
)
|
26
|
+
);
|
27
|
+
|
28
|
+
return (
|
29
|
+
// Approach 1: Use MApp to automatically load sub-applications based on the configured activeWhen parameter (this project is configured in modern.config.ts)
|
30
|
+
// <BrowserRouter>
|
31
|
+
// <MApp />
|
32
|
+
// </BrowserRouter>
|
33
|
+
|
34
|
+
// Approach 2: Manually write Route components to load sub-applications, which is convenient for scenarios that require authentication and other pre-requisite operations
|
35
|
+
<>
|
36
|
+
<RouterProvider router={router} />
|
37
|
+
</>
|
38
|
+
);
|
39
|
+
};
|
40
|
+
```
|
@@ -23,7 +23,7 @@ export default defineConfig({
|
|
23
23
|
});
|
24
24
|
```
|
25
25
|
|
26
|
-
After configuring `output.polyfill` as `ua` and executing `pnpm run build & & pnpm run serve` to start the server, visiting the page can see that the HTML
|
26
|
+
After configuring `output.polyfill` as `ua` and executing `pnpm run build & & pnpm run serve` to start the server, visiting the page can see that the HTML artifacts contains the following script:
|
27
27
|
|
28
28
|
```js
|
29
29
|
<script src="/__polyfill__" crossorigin></script>
|
@@ -24,7 +24,7 @@ export default defineConfig({
|
|
24
24
|
|
25
25
|
### Auto Registration plugin
|
26
26
|
|
27
|
-
In addition to means registration, Modern.js also provides a way to automatically register plugins: set the `autoLoadPlugin` configuration
|
27
|
+
In addition to means registration, Modern.js also provides a way to automatically register plugins: set the `autoLoadPlugin` configuration option to `true`.
|
28
28
|
|
29
29
|
```ts title="modern.config.ts"
|
30
30
|
import { defineConfig } from '@modern-js/app-tools';
|
@@ -28,13 +28,13 @@ export default defineConfig({
|
|
28
28
|
|
29
29
|
Assuming the address of Modern.js BFF server is `localhost:8080`, all requests starting with `api` will be proxied to `https://cnodejs.org`, for example, the request to `localhost:8080/api/v1/topics` will be proxied to `https://cnodejs.org/api/v1/topics`.
|
30
30
|
|
31
|
-
import BFFProxyPathRewrite from "@site-docs/components/bff-proxy-path-rewrite";
|
31
|
+
import BFFProxyPathRewrite from "@site-docs-en/components/bff-proxy-path-rewrite";
|
32
32
|
|
33
33
|
<BFFProxyPathRewrite />
|
34
34
|
|
35
35
|
Unlike [dev.proxy](/configure/app/dev/proxy), the proxy here only applies to requests entering the BFF/API service; at the same time, this configuration can not only be used in the development environment, but also proxies corresponding requests in the production environment.
|
36
36
|
|
37
|
-
import BFFProxyPrinciple from "@site-docs/components/bff-proxy-principle";
|
37
|
+
import BFFProxyPrinciple from "@site-docs-en/components/bff-proxy-principle";
|
38
38
|
|
39
39
|
<BFFProxyPrinciple />
|
40
40
|
|
@@ -53,7 +53,7 @@ export default defineConfig({
|
|
53
53
|
});
|
54
54
|
```
|
55
55
|
|
56
|
-
### Plugin configuration
|
56
|
+
### Plugin configuration options
|
57
57
|
|
58
58
|
If the plugin provides some custom configuration options, you can pass in the configuration through the parameters of the plugin function.
|
59
59
|
|
@@ -37,4 +37,4 @@ interface AppInfo {
|
|
37
37
|
|
38
38
|
In the `masterApp` configuration, developers can pass through options supported by Garfish
|
39
39
|
|
40
|
-
All supported configuration
|
40
|
+
All supported configuration options [see here](https://garfishjs.org/api/run/#%E5%8F%82%E6%95%B0).
|
@@ -32,14 +32,15 @@ When the value type is `Object`, the following properties can be configured:
|
|
32
32
|
```ts title="modern.config.ts"
|
33
33
|
export default defineConfig({
|
34
34
|
server: {
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
ssr: {
|
36
|
+
forceCSR: true,
|
37
|
+
mode: 'stream',
|
38
|
+
inlineScript: false,
|
39
|
+
},
|
38
40
|
},
|
39
41
|
});
|
40
42
|
```
|
41
43
|
|
42
|
-
|
43
44
|
### Active Fallback
|
44
45
|
|
45
46
|
In a production environment, there are scenarios where it is necessary to actively fallback an SSR project to CSR. Examples include
|
@@ -50,7 +51,7 @@ In a production environment, there are scenarios where it is necessary to active
|
|
50
51
|
|
51
52
|
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
|
|
53
|
-
By configuring `ssr.
|
54
|
+
By configuring `server.ssr.forceCSR` to `true` in the project, you can control this behavior through query strings or request headers.
|
54
55
|
|
55
56
|
For example, in a custom Web Server middleware, you can actively fallback when traffic exceeds a certain threshold:
|
56
57
|
|
@@ -15,6 +15,8 @@ import SWC from '@modern-js/builder-doc/docs/en/shared/swc.md';
|
|
15
15
|
|
16
16
|
:::tip
|
17
17
|
When using Rspack as the bundler, SWC will be used for transpiling and compression by default, so you don't need to install or configure the SWC plugin.
|
18
|
+
|
19
|
+
If you have configured the current SWC plugin when using Rspack, it will not have any effect.
|
18
20
|
:::
|
19
21
|
|
20
22
|
## Install
|
@@ -1,6 +1,7 @@
|
|
1
1
|
---
|
2
2
|
title: BFF
|
3
3
|
---
|
4
|
+
|
4
5
|
# BFF
|
5
6
|
|
6
7
|
In the development of the concept of **front back separation**, the front-end part can do more and more things, and the front-end needs some UI-oriented data interfaces, so the industry introduced the concept of BFF (Backends for Frontends).
|
@@ -16,7 +16,7 @@ When using Modern.js [Conventional routing](/guides/basic-features/routes#conven
|
|
16
16
|
|
17
17
|
## import
|
18
18
|
|
19
|
-
use dynamic `import()`, the JS modules pass to this API will be
|
19
|
+
use dynamic `import()`, the JS modules pass to this API will be bundled as a separate JS file, for example:
|
20
20
|
|
21
21
|
```ts
|
22
22
|
import('./math').then(math => {
|
@@ -92,4 +92,4 @@ Usually it is available and any errors that arise will fixed promptly.
|
|
92
92
|
However, if there are any break changes that require modern.js to modify the code, we recommend to wait for the next version of modern.js.
|
93
93
|
:::
|
94
94
|
|
95
|
-
More examples of using package
|
95
|
+
More examples of using package managers, please refer to: [Lock nested dependency](/guides/get-started/upgrade.html#lock-nested-dependency).
|
@@ -251,7 +251,7 @@ if (process.env.MODERN_TARGET === 'browser') {
|
|
251
251
|
}
|
252
252
|
```
|
253
253
|
|
254
|
-
After the development environment is
|
254
|
+
After the development environment is bundled, the SSR and CSR artifacts will be compiled into the following content. Therefore, there will be no more Web API errors in the SSR environment.
|
255
255
|
|
256
256
|
```ts
|
257
257
|
// SSR production
|
@@ -336,7 +336,7 @@ export default async (): Promise<ProfileData> => {
|
|
336
336
|
};
|
337
337
|
```
|
338
338
|
|
339
|
-
4. When running on the server, the `loader` function will be
|
339
|
+
4. When running on the server, the `loader` function will be bundled into a unified bundle, so we do not recommend using `__filename` and `__dirname` in server-side code.
|
340
340
|
|
341
341
|
### FAQ
|
342
342
|
|
@@ -13,7 +13,7 @@ import Prerequisites from "@site-docs-en/components/prerequisites"
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
|
-
Modern.js provides the `@modern-js/create` tool to create projects.
|
16
|
+
Modern.js provides the `@modern-js/create` tool to create projects. It does not require global installation and can be run on-demand using `npx`.
|
17
17
|
|
18
18
|
You can create a project in an existing empty directory:
|
19
19
|
|
@@ -47,21 +47,41 @@ In a Modern.js project created using `@modern-js/create`, a `modern.config.ts` f
|
|
47
47
|
You can modify the configuration through this file to override the default behavior of Modern.js. For example, to enable SSR, add the following configuration:
|
48
48
|
|
49
49
|
```ts
|
50
|
-
import { defineConfig } from '@modern-js/app-tools';
|
50
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
51
51
|
|
52
52
|
export default defineConfig({
|
53
53
|
runtime: {
|
54
54
|
router: true,
|
55
|
-
state: true,
|
56
55
|
},
|
57
56
|
server: {
|
58
57
|
ssr: true,
|
59
58
|
},
|
59
|
+
plugins: [appTools()],
|
60
60
|
});
|
61
61
|
```
|
62
62
|
|
63
63
|
After running `pnpm run dev` again, you can find that the project has completed page rendering on the server in the browser's Network menu.
|
64
64
|
|
65
|
+
## Core npm Package
|
66
|
+
|
67
|
+
In a newly created project, the `@modern-js/app-tools` npm package is installed by default. It is the core package of the Modern.js framework and provides the following capabilities:
|
68
|
+
|
69
|
+
- It offers commonly used CLI commands such as `modern dev`, `modern build`, and more.
|
70
|
+
- It integrates Modern.js Core, providing capabilities for configuration parsing, plugin loading, and more.
|
71
|
+
- It integrates Modern.js Builder, providing build capabilities.
|
72
|
+
- It integrates Modern.js Server, providing capabilities for development and production servers.
|
73
|
+
- It integrates some commonly used plugins, such as `plugin-lint`, `plugin-data-loader`, and more.
|
74
|
+
|
75
|
+
`@modern-js/app-tools` is implemented based on the plugin system of Modern.js. Essentially, it is a plugin. Therefore, you need to register `appTools` in the `plugins` field of the configuration file:
|
76
|
+
|
77
|
+
```ts title="modern.config.ts"
|
78
|
+
import { appTools, defineConfig } from '@modern-js/app-tools';
|
79
|
+
|
80
|
+
export default defineConfig({
|
81
|
+
plugins: [appTools()],
|
82
|
+
});
|
83
|
+
```
|
84
|
+
|
65
85
|
## Build the project
|
66
86
|
|
67
87
|
To build the production artifacts of the project, run `pnpm run build` in the project:
|
@@ -19,7 +19,7 @@ A changeset includes:
|
|
19
19
|
## Steps
|
20
20
|
|
21
21
|
:::info
|
22
|
-
The following example commands are all using pnpm. If you need to use other package
|
22
|
+
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
|
23
23
|
:::
|
24
24
|
|
25
25
|
### NPM Module
|
@@ -9,7 +9,7 @@ Before doing an actual release, we also need to publish a pre-release version fo
|
|
9
9
|
## Steps
|
10
10
|
|
11
11
|
:::info
|
12
|
-
The following example commands are all using pnpm. If you need to use other package
|
12
|
+
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
|
13
13
|
:::
|
14
14
|
|
15
15
|
#### Run the bump command to upgrade the version of the pre-release
|
@@ -9,7 +9,7 @@ When releasing a version, we need to upgrade the version of the corresponding pa
|
|
9
9
|
## Steps
|
10
10
|
|
11
11
|
:::info
|
12
|
-
The following example commands are all using pnpm. If you need to use other package
|
12
|
+
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
|
13
13
|
|
14
14
|
:::
|
15
15
|
|
@@ -299,10 +299,21 @@ export const myPlugin = (): CliPlugin => ({
|
|
299
299
|
|
300
300
|
### `beforeCreateCompiler`
|
301
301
|
|
302
|
-
- Function:
|
303
|
-
-
|
304
|
-
-
|
305
|
-
-
|
302
|
+
- Function: A callback function triggered before creating the underlying Compiler instance, and you can get the final configuration array of the underlying bundler through the `bundlerConfigs` parameter:
|
303
|
+
- If the current bundler is webpack, you will get the webpack Compiler object.
|
304
|
+
- If the current bundler is Rspack, you will get the Rspack Compiler object.
|
305
|
+
- The configuration array may contain one or multiple configurations, depending on whether you have enabled features such as SSR.
|
306
|
+
- Execution Stage: Executed before creating the Compiler instance when running the `dev` or `build` command.
|
307
|
+
- Hook Model: `AsyncWorkflow`.
|
308
|
+
- Type:
|
309
|
+
|
310
|
+
```ts
|
311
|
+
type BeforeCreateCompiler = AsyncWorkflow<
|
312
|
+
{ bundlerConfigs: Configuration[] },
|
313
|
+
unknown
|
314
|
+
>;
|
315
|
+
```
|
316
|
+
|
306
317
|
- Usage Example:
|
307
318
|
|
308
319
|
```ts
|
@@ -311,8 +322,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
311
322
|
export const myPlugin = (): CliPlugin => ({
|
312
323
|
setup(api) {
|
313
324
|
return {
|
314
|
-
beforeCreateCompiler: ({
|
315
|
-
|
325
|
+
beforeCreateCompiler: ({ bundlerConfigs }) => {
|
326
|
+
console.log('Before create compiler.');
|
327
|
+
console.log(bundlerConfigs);
|
316
328
|
},
|
317
329
|
};
|
318
330
|
},
|
@@ -321,10 +333,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
321
333
|
|
322
334
|
### `afterCreateCompiler`
|
323
335
|
|
324
|
-
- Function:
|
325
|
-
-
|
326
|
-
-
|
327
|
-
-
|
336
|
+
- Function: A callback function triggered after creating a Compiler instance and before executing the build. You can access the Compiler instance object through the `compiler` parameter:
|
337
|
+
- If the current bundler is webpack, you will get the webpack Compiler object.
|
338
|
+
- If the current bundler is Rspack, you will get the Rspack Compiler object.
|
339
|
+
- Execution Stage: Executed after creating the Compiler object.
|
340
|
+
- Hook Model: `AsyncWorkflow`.
|
341
|
+
- Type:
|
342
|
+
|
343
|
+
```ts
|
344
|
+
type AfterCreateCompiler = AsyncWorkflow<
|
345
|
+
{ compiler: Compiler | MultiCompiler | undefined },
|
346
|
+
unknown
|
347
|
+
>;
|
348
|
+
```
|
349
|
+
|
328
350
|
- Usage Example:
|
329
351
|
|
330
352
|
```ts
|
@@ -334,7 +356,8 @@ export const myPlugin = (): CliPlugin => ({
|
|
334
356
|
setup(api) {
|
335
357
|
return {
|
336
358
|
afterCreateCompiler: ({ compiler }) => {
|
337
|
-
|
359
|
+
console.log('After create compiler.');
|
360
|
+
console.log(compiler);
|
338
361
|
},
|
339
362
|
};
|
340
363
|
},
|
@@ -368,10 +391,20 @@ export const myPlugin = (): CliPlugin => ({
|
|
368
391
|
|
369
392
|
### `beforeBuild`
|
370
393
|
|
371
|
-
- Function:
|
372
|
-
-
|
373
|
-
-
|
374
|
-
-
|
394
|
+
- Function: A callback function triggered before executing production environment builds. You can access the final configuration array of the underlying bundler through the `bundlerConfigs` parameter.
|
395
|
+
- If the current bundler is webpack, you will get the webpack Compiler object.
|
396
|
+
- If the current bundler is Rspack, you will get the Rspack Compiler object.
|
397
|
+
- The configuration array may contain one or multiple configurations, depending on whether you have enabled features such as SSR.
|
398
|
+
- Execution Stage: Executed after running the `build` command and before the actual build process begins.
|
399
|
+
- Hook Model: `AsyncWorkflow`.
|
400
|
+
- Type:
|
401
|
+
|
402
|
+
```ts
|
403
|
+
type BeforeBuild = AsyncWorkflow<{
|
404
|
+
bundlerConfigs: WebpackConfig[] | RspackConfig[];
|
405
|
+
}>;
|
406
|
+
```
|
407
|
+
|
375
408
|
- Usage Example:
|
376
409
|
|
377
410
|
```ts
|
@@ -380,8 +413,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
380
413
|
export const myPlugin = (): CliPlugin => ({
|
381
414
|
setup(api) {
|
382
415
|
return {
|
383
|
-
beforeBuild: () => {
|
384
|
-
|
416
|
+
beforeBuild: ({ bundlerConfigs }) => {
|
417
|
+
console.log('Before build.');
|
418
|
+
console.log(bundlerConfigs);
|
385
419
|
},
|
386
420
|
};
|
387
421
|
},
|
@@ -390,10 +424,19 @@ export const myPlugin = (): CliPlugin => ({
|
|
390
424
|
|
391
425
|
### `afterBuild`
|
392
426
|
|
393
|
-
- Function:
|
394
|
-
-
|
395
|
-
-
|
396
|
-
-
|
427
|
+
- Function: A callback function triggered after running the production build. You can access the build result information through the `stats` parameter.
|
428
|
+
- If the current bundler is webpack, you will get webpack Stats.
|
429
|
+
- If the current bundler is Rspack, you will get Rspack Stats.
|
430
|
+
- Execution Stage: It is executed after running the `build` command and completing the build.
|
431
|
+
- Hook Model: `AsyncWorkflow`.
|
432
|
+
- Type:
|
433
|
+
|
434
|
+
```ts
|
435
|
+
type AfterBuild = AsyncWorkflow<{
|
436
|
+
stats?: Stats | MultiStats;
|
437
|
+
}>;
|
438
|
+
```
|
439
|
+
|
397
440
|
- Usage Example:
|
398
441
|
|
399
442
|
```ts
|
@@ -402,8 +445,9 @@ import type { CliPlugin } from '@modern-js/core';
|
|
402
445
|
export const myPlugin = (): CliPlugin => ({
|
403
446
|
setup(api) {
|
404
447
|
return {
|
405
|
-
afterBuild: () => {
|
406
|
-
|
448
|
+
afterBuild: ({ stats }) => {
|
449
|
+
console.log('After build.');
|
450
|
+
console.log(stats);
|
407
451
|
},
|
408
452
|
};
|
409
453
|
},
|
@@ -65,9 +65,9 @@ By default, `@modern-js/create` will automatically identify the user's system la
|
|
65
65
|
|
66
66
|
Specify the default project configuration.
|
67
67
|
|
68
|
-
By default, `@modern-js/create` will prompt for interactive questions such as language selection and package
|
68
|
+
By default, `@modern-js/create` will prompt for interactive questions such as language selection and package managers during the execution process. When it is necessary to specify these configuration contents in advance, they can be passed in through this field.
|
69
69
|
|
70
|
-
This field is a JSON string. For example, when specifying a package
|
70
|
+
This field is a JSON string. For example, when specifying a package manager:
|
71
71
|
|
72
72
|
```bash
|
73
73
|
npx @modern-js/create@latest --config '{"packageManager": "pnpm"}'
|
@@ -122,7 +122,7 @@ npx @modern-js/create@next --dist-tag next
|
|
122
122
|
|
123
123
|
Specify specific package version dependencies when creating a project.
|
124
124
|
|
125
|
-
If you need to specify a specific package version when creating a project, you can use this parameter. This parameter will configure `pnpm.overrides` (if the package
|
125
|
+
If you need to specify a specific package version when creating a project, you can use this parameter. This parameter will configure `pnpm.overrides` (if the package manager is pnpm) or `resolutions` to lock the package version number in the `package.json` file in the project root directory.
|
126
126
|
|
127
127
|
The parameter value is a JSON string.
|
128
128
|
|
@@ -46,4 +46,4 @@ Parameters:
|
|
46
46
|
|
47
47
|
### install
|
48
48
|
|
49
|
-
Installs dependencies in the root directory of the project. The `install` function will use the corresponding package
|
49
|
+
Installs dependencies in the root directory of the project. The `install` function will use the corresponding package manager according to the value of `packageManager` to install dependencies.
|
@@ -215,7 +215,7 @@ Parameter types:
|
|
215
215
|
updateInfo: Record<string, any>
|
216
216
|
```
|
217
217
|
|
218
|
-
- `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `
|
218
|
+
- `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `modernConfig` field. Only the configuration fields under `modernConfig` need to be filled in `updateInfo`.
|
219
219
|
|
220
220
|
For example, enable SSR:
|
221
221
|
|
@@ -39,7 +39,7 @@ After the project is created, we can enable the `micro frontend` through `pnpm r
|
|
39
39
|
|
40
40
|
Next, let's register the micro frontend plugin and add the main micro frontend app and add the list of sub-apps:
|
41
41
|
|
42
|
-
import EnableMicroFrontend from "@site-docs/components/enable-micro-frontend";
|
42
|
+
import EnableMicroFrontend from "@site-docs-en/components/enable-micro-frontend";
|
43
43
|
|
44
44
|
<EnableMicroFrontend />
|
45
45
|
|
@@ -127,7 +127,7 @@ Since it is a self-controlled route, we delete the `routes/` folder and add the
|
|
127
127
|
|
128
128
|
#### Load sub-app
|
129
129
|
|
130
|
-
import CustomRouterMicroFrontend from "@site-docs/components/custom-router-micro-frontend";
|
130
|
+
import CustomRouterMicroFrontend from "@site-docs-en/components/custom-router-micro-frontend";
|
131
131
|
|
132
132
|
<CustomRouterMicroFrontend />
|
133
133
|
|
@@ -8,7 +8,7 @@ In the previous [Experience micro frontend](/guides/topic-detail/micro-frontend/
|
|
8
8
|
|
9
9
|
After creating an application project through the `@modern-js/create` command, you can execute `pnpm run new` in the project (the `modern new` command is actually executed). After selecting the 「micro frontend」 mode, the micro frontend will be installed. Dependencies, just register the plugin manually.
|
10
10
|
|
11
|
-
import EnableMicroFrontend from "@site-docs/components/enable-micro-frontend";
|
11
|
+
import EnableMicroFrontend from "@site-docs-en/components/enable-micro-frontend";
|
12
12
|
|
13
13
|
<EnableMicroFrontend />
|
14
14
|
|
@@ -23,10 +23,10 @@ You can register the sub-application information directly through the configurat
|
|
23
23
|
:::tip
|
24
24
|
It can be configured at runtime via the API [defineConfig](/apis/app/runtime/app/define-config).
|
25
25
|
|
26
|
-
When the parameter is a function, it cannot be serialized to the
|
26
|
+
When the parameter is a function, it cannot be serialized to the output code, so please configure it through defineConfig when it comes to configuration such as functions
|
27
27
|
:::
|
28
28
|
|
29
|
-
import MicroRuntimeConfig from "@site-docs/components/micro-runtime-config";
|
29
|
+
import MicroRuntimeConfig from "@site-docs-en/components/micro-runtime-config";
|
30
30
|
|
31
31
|
<MicroRuntimeConfig />
|
32
32
|
|
@@ -248,5 +248,5 @@ const handleClick = async () => {
|
|
248
248
|
```
|
249
249
|
|
250
250
|
:::info
|
251
|
-
[Example](https://github.com/web-infra-dev/modern-js-examples/tree/main/
|
251
|
+
[Example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/effects)
|
252
252
|
:::
|
@@ -100,7 +100,7 @@ The final effect is as follows:
|
|
100
100
|

|
101
101
|
|
102
102
|
:::info Additional Information
|
103
|
-
- Full example code for this section can be found [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/
|
103
|
+
- Full example code for this section can be found [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/models-communication).
|
104
104
|
- For more information about the relevant API, please refer to: [model](/apis/app/runtime/model/model_#function-types).
|
105
105
|
|
106
106
|
:::
|
@@ -165,6 +165,6 @@ const barModel = model("bar").define({
|
|
165
165
|
We created a caching function `createSelector`, which only recalculates the value of `combineA` when the state of `barModel` changes or the state `a` of `fooModel` changes.
|
166
166
|
|
167
167
|
:::info Additional Information
|
168
|
-
You can find the complete example code of this section [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/
|
168
|
+
You can find the complete example code of this section [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/performance-optimization).
|
169
169
|
:::
|
170
170
|
|
@@ -4,7 +4,7 @@ title: Quick Start
|
|
4
4
|
---
|
5
5
|
# Quick Start
|
6
6
|
|
7
|
-
import ReduckMigration from "@site-docs/components/reduck-migration"
|
7
|
+
import ReduckMigration from "@site-docs-en/components/reduck-migration"
|
8
8
|
|
9
9
|
<ReduckMigration />
|
10
10
|
|
@@ -110,5 +110,5 @@ The final demonstration effect is as follows:
|
|
110
110
|
|
111
111
|

|
112
112
|
|
113
|
-
That completes a simple counter application. You can view the complete example code for this section [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/
|
113
|
+
That completes a simple counter application. You can view the complete example code for this section [here](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/counter-model).
|
114
114
|
|