@modern-js/main-doc 2.67.11 → 2.68.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/docs/en/apis/app/runtime/web-server/hook.mdx +3 -7
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -9
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +7 -0
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +11 -0
- package/docs/en/configure/app/source/include.mdx +34 -7
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +5 -6
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +2 -7
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +6 -0
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +10 -0
- package/docs/zh/configure/app/source/include.mdx +34 -5
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/package.json +2 -2
@@ -4,18 +4,14 @@ title: Hook
|
|
4
4
|
|
5
5
|
# Hook
|
6
6
|
|
7
|
-
Used to extend Modern.js built-in Web Server, all page requests are handled by these hooks.
|
8
|
-
|
9
7
|
:::warning
|
10
|
-
It is recommended to use [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware) to handle page requests.
|
11
|
-
|
12
|
-
:::
|
13
8
|
|
14
|
-
|
15
|
-
For more detail, see [Extend Web Server](/guides/advanced-features/web-server).
|
9
|
+
The Hook API has been deprecated. Please use the [new Custom Web Server](/guides/advanced-features/web-server) to handle page requests.
|
16
10
|
|
17
11
|
:::
|
18
12
|
|
13
|
+
Used to extend Modern.js built-in Web Server, all page requests are handled by these hooks.
|
14
|
+
|
19
15
|
## Usage
|
20
16
|
|
21
17
|
```ts
|
@@ -4,21 +4,14 @@ title: Middleware
|
|
4
4
|
|
5
5
|
# Middleware
|
6
6
|
|
7
|
-
Used to extend the built-in Web Server of Modern.js, unlike [Hook](/apis/app/runtime/web-server/hook), Middleware can directly operate Node's origin request and response, and can be extended using the framework plugin.
|
8
|
-
|
9
7
|
:::warning
|
10
8
|
|
11
|
-
Middleware
|
12
|
-
|
13
|
-
It is recommended to use [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware) to handle page requests.
|
9
|
+
Middleware has been deprecated. Please use the [new Custom Web Server](/guides/advanced-features/web-server) to handle page requests.
|
14
10
|
|
15
11
|
:::
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
For more detail, see [Extend Web Server](/guides/advanced-features/web-server).
|
13
|
+
Used to extend the built-in Web Server of Modern.js, unlike [Hook](/apis/app/runtime/web-server/hook), Middleware can directly operate Node's origin request and response, and can be extended using the framework plugin.
|
20
14
|
|
21
|
-
:::
|
22
15
|
|
23
16
|
## Usage
|
24
17
|
|
@@ -4,9 +4,16 @@ title: Unstable Middleware
|
|
4
4
|
|
5
5
|
# Unstable Middleware
|
6
6
|
|
7
|
+
:::warning
|
8
|
+
|
9
|
+
UnstableMiddleware has been deprecated. Please use the [new Custom Web Server](/guides/advanced-features/web-server) to handle page requests.
|
10
|
+
|
11
|
+
:::
|
12
|
+
|
7
13
|
Used to extend the built-in Web Server in Modern.js.
|
8
14
|
UnstableMiddleware will replace [Middleware](/apis/app/runtime/web-server/middleware) in the future.
|
9
15
|
|
16
|
+
|
10
17
|
## Usage
|
11
18
|
|
12
19
|
```ts title="server/index.ts"
|
@@ -25,6 +25,17 @@ Used to enable the lazy compilation (i.e. compile on demand). When this config i
|
|
25
25
|
|
26
26
|
Lazy compilation only takes effect in the development.
|
27
27
|
|
28
|
+
## Rspack
|
29
|
+
|
30
|
+
import RsbuildLink from '@site/src/components/RsbuildLink';
|
31
|
+
|
32
|
+
:::info
|
33
|
+
The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to <RsbuildLink configName="dev.lazyCompilation"/>。
|
34
|
+
In Rspack build mode,
|
35
|
+
:::
|
36
|
+
|
37
|
+
## Webapck
|
38
|
+
|
28
39
|
### Lazy Compilation for Dynamic Imports
|
29
40
|
|
30
41
|
Lazy compile async modules introduced by [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import):
|
@@ -5,21 +5,48 @@ title: include
|
|
5
5
|
# source.include
|
6
6
|
|
7
7
|
- **Type:** [RuleSetCondition[]](https://rspack.rs/config/module#condition)
|
8
|
-
- **Default:**
|
8
|
+
- **Default value:**
|
9
9
|
|
10
10
|
```ts
|
11
11
|
const defaultInclude = [
|
12
12
|
[
|
13
|
-
/node_modules
|
14
|
-
|
15
|
-
/node_modules\/@remix-run\/router/,
|
16
|
-
'/node_modules/.modern-js',
|
13
|
+
{ not: /[\\/]node_modules[\\/]/ },
|
14
|
+
/\.(?:ts|tsx|jsx|mts|cts)$/,
|
17
15
|
],
|
18
16
|
];
|
19
17
|
```
|
20
18
|
|
21
|
-
|
19
|
+
`source.include` is used to specify additional JavaScript files that need to be compiled. By default, the following files will be compiled:
|
22
20
|
|
23
|
-
|
21
|
+
- TypeScript and JSX files in any directory, with file extensions matching `.ts`, `.tsx`, `.jsx`, `.mts`, `.cts`.
|
22
|
+
- JavaScript files not in the `node_modules` directory, with file extensions matching `.js`, `.mjs`, `.cjs`.
|
23
|
+
|
24
|
+
:::tip
|
25
|
+
Before Rsbuild version 1.4, the default value of `source.include` was:
|
26
|
+
|
27
|
+
```ts
|
28
|
+
const defaultInclude = [
|
29
|
+
[
|
30
|
+
{
|
31
|
+
and: [
|
32
|
+
APP_ROOT,
|
33
|
+
{ not: /[\\/]node_modules[\\/]/ }
|
34
|
+
]
|
35
|
+
},
|
36
|
+
/\.(?:ts|tsx|jsx|mts|cts)$/,
|
37
|
+
],
|
38
|
+
];
|
39
|
+
```
|
40
|
+
|
41
|
+
The difference from the new version is that `.js`, `.mjs`, `.cjs` files only in the current directory will be compiled.
|
42
|
+
:::
|
43
|
+
|
44
|
+
## Rspack
|
45
|
+
|
46
|
+
import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
|
24
47
|
|
25
48
|
<RsbuildConfig configName="source.include" />
|
49
|
+
|
50
|
+
## Webpack
|
51
|
+
|
52
|
+
To ensure legacy projects can run properly, when using Webpack, the default value of `source.include` is the same as before Rsbuild version 1.4.
|
@@ -4,16 +4,15 @@ title: Hook
|
|
4
4
|
|
5
5
|
# Hook
|
6
6
|
|
7
|
-
用于拓展 Modern.js 内置的 Web Server,所有的页面请求都会经过 Hook。
|
8
|
-
|
9
7
|
:::warning
|
10
|
-
推荐使用 [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware) 来处理页面请求。
|
11
|
-
:::
|
12
8
|
|
13
|
-
|
14
|
-
|
9
|
+
Hook API 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
10
|
+
|
15
11
|
:::
|
16
12
|
|
13
|
+
用于拓展 Modern.js 内置的 Web Server,所有的页面请求都会经过 Hook。
|
14
|
+
|
15
|
+
|
17
16
|
## 使用姿势
|
18
17
|
|
19
18
|
```ts
|
@@ -4,19 +4,14 @@ title: Middleware
|
|
4
4
|
|
5
5
|
# Middleware
|
6
6
|
|
7
|
-
用于拓展 Modern.js 内置的 Web Server,与 [Hook](/apis/app/runtime/web-server/hook) 不同的是,Middleware 可以直接操作 Node 原生的请求、响应对象,并且可以使用框架拓展。
|
8
|
-
|
9
7
|
:::warning
|
10
8
|
|
11
|
-
Middleware
|
9
|
+
Middleware 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
12
10
|
|
13
11
|
:::
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
更多内容可以查看[自定义 Web Server](/guides/advanced-features/web-server)。
|
13
|
+
用于拓展 Modern.js 内置的 Web Server,与 [Hook](/apis/app/runtime/web-server/hook) 不同的是,Middleware 可以直接操作 Node 原生的请求、响应对象,并且可以使用框架拓展。
|
18
14
|
|
19
|
-
:::
|
20
15
|
|
21
16
|
## 使用姿势
|
22
17
|
|
@@ -4,6 +4,12 @@ title: Unstable Middleware
|
|
4
4
|
|
5
5
|
# Unstable Middleware
|
6
6
|
|
7
|
+
:::warning
|
8
|
+
|
9
|
+
Unstable Middleware 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
10
|
+
|
11
|
+
:::
|
12
|
+
|
7
13
|
用于拓展 Modern.js 内置的 Web Server。 未来 UnstableMiddleware 将替代 [Middleware](/apis/app/runtime/web-server/middleware)
|
8
14
|
|
9
15
|
## 使用
|
@@ -25,6 +25,16 @@ type LazyCompilationOptions =
|
|
25
25
|
|
26
26
|
延迟编译只在开发环境下生效。
|
27
27
|
|
28
|
+
## Rspack
|
29
|
+
|
30
|
+
import RsbuildLink from '@site/src/components/RsbuildLink';
|
31
|
+
|
32
|
+
:::info
|
33
|
+
该配置项的使用方式与 Rsbuild 完全一致,详细信息可参考 <RsbuildLink configName="dev.lazyCompilation"/>。
|
34
|
+
:::
|
35
|
+
|
36
|
+
## Webpack
|
37
|
+
|
28
38
|
### 延迟编译异步模块
|
29
39
|
|
30
40
|
延迟编译 [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) 引入的异步模块:
|
@@ -10,16 +10,45 @@ title: include
|
|
10
10
|
```ts
|
11
11
|
const defaultInclude = [
|
12
12
|
[
|
13
|
-
/node_modules
|
14
|
-
|
15
|
-
/node_modules\/@remix-run\/router/,
|
16
|
-
'/node_modules/.modern-js',
|
13
|
+
{ not: /[\\/]node_modules[\\/]/ },
|
14
|
+
/\.(?:ts|tsx|jsx|mts|cts)$/,
|
17
15
|
],
|
18
16
|
];
|
19
17
|
```
|
20
18
|
|
21
|
-
`source.include` 用于指定额外需要编译的 JavaScript
|
19
|
+
`source.include` 用于指定额外需要编译的 JavaScript 文件。默认情况下,会编译以下文件:
|
20
|
+
|
21
|
+
- 任意目录下的 TypeScript 和 JSX 文件,匹配的文件后缀为 `.ts`、`.tsx`、`.jsx`、`.mts`、`.cts`。
|
22
|
+
- 非 `node_modules` 目录下的 JavaScript 文件,匹配的文件后缀为 `.js`、`.mjs`、`.cjs`。
|
23
|
+
|
24
|
+
:::tip
|
25
|
+
在 Rsbuild 1.4 版本前,`source.include` 的默认值为:
|
26
|
+
|
27
|
+
```ts
|
28
|
+
const defaultInclude = [
|
29
|
+
[
|
30
|
+
{
|
31
|
+
and: [
|
32
|
+
APP_ROOT,
|
33
|
+
{ not: /[\\/]node_modules[\\/]/ }
|
34
|
+
]
|
35
|
+
},
|
36
|
+
/\.(?:ts|tsx|jsx|mts|cts)$/,
|
37
|
+
],
|
38
|
+
];
|
39
|
+
```
|
40
|
+
|
41
|
+
与新版本的差异是,非当前项目目录的 `.js`、`.mjs`、`.cjs` 文件不会被编译。
|
42
|
+
:::
|
43
|
+
|
44
|
+
## Rspack
|
22
45
|
|
23
46
|
import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
|
24
47
|
|
25
48
|
<RsbuildConfig configName="source.include" />
|
49
|
+
|
50
|
+
## Webpack
|
51
|
+
|
52
|
+
为了保证历史项目可以正常运行,Webpack 编译时,`source.include` 与 Rsbuild 1.4 版本前的默认值一致。
|
53
|
+
|
54
|
+
|
@@ -304,11 +304,11 @@ export default (props: { basename: string }) => {
|
|
304
304
|
使用纯 `Garfish` API 开发微前端应用时
|
305
305
|
|
306
306
|
- 主应用:
|
307
|
-
- 安装 Garfish 依赖并使用 `Garfish.run` 注册子应用 [参考](https://www.garfishjs.org/api/run)
|
308
|
-
- 提供一个常驻的 `DOM` 节点供子应用挂载 [参考](https://www.garfishjs.org/api/registerApp
|
307
|
+
- 安装 Garfish 依赖并使用 `Garfish.run` 注册子应用 [参考](https://www.garfishjs.org/api/run.html)
|
308
|
+
- 提供一个常驻的 `DOM` 节点供子应用挂载 [参考](https://www.garfishjs.org/api/registerApp.html)
|
309
309
|
- 子应用:
|
310
|
-
- 导出 `provider` [参考](https://www.garfishjs.org/guide/start#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)
|
311
|
-
- 设置应用的 `basename` [参考](https://www.garfishjs.org/guide/start#3-%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E8%B7%AF%E7%94%B1-basename)
|
310
|
+
- 导出 `provider` [参考](https://www.garfishjs.org/guide/quick-start/start.html#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)
|
311
|
+
- 设置应用的 `basename` [参考](https://www.garfishjs.org/guide/quick-start/start.html#3-%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E8%B7%AF%E7%94%B1-basename)
|
312
312
|
|
313
313
|
区别于直接使用 `Garfish` 运行时 API 开发微前端项目,`Modern.js` 的微前端方案更加开箱即用。
|
314
314
|
使用 `pnpm new` 启用微前端模式后会自动在 `Modern.js` 应用中集成 `Garfish` 插件,在 `Garfish`
|
package/package.json
CHANGED
@@ -15,14 +15,14 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.68.0",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
24
|
"mermaid": "^11.4.1",
|
25
|
-
"@modern-js/sandpack-react": "2.
|
25
|
+
"@modern-js/sandpack-react": "2.68.0"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"@rsbuild/plugin-sass": "1.3.2",
|