@modern-js/main-doc 2.18.0 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/docs/en/components/convention-routing-movitation.mdx +0 -0
- package/docs/en/components/routes-practice.mdx +0 -0
- package/docs/en/configure/app/tools/esbuild.mdx +2 -3
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/basic-features/data-fetch.mdx +8 -0
- package/docs/en/guides/basic-features/routes.mdx +16 -0
- package/docs/en/guides/get-started/glossary.mdx +63 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
- package/docs/zh/components/convention-routing-movitation.mdx +0 -0
- package/docs/zh/components/routes-practice.mdx +0 -0
- package/docs/zh/configure/app/tools/esbuild.mdx +2 -2
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/basic-features/data-fetch.mdx +9 -0
- package/docs/zh/guides/basic-features/routes.mdx +17 -2
- package/docs/zh/guides/get-started/glossary.mdx +63 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# @modern-js/main-doc
|
2
2
|
|
3
|
+
## 2.19.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/builder-doc@2.19.0
|
8
|
+
|
9
|
+
## 2.18.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 21c87bf: feat: bump codesmith packages version
|
14
|
+
|
15
|
+
feat: 升级 codesmith 包版本
|
16
|
+
|
17
|
+
- @modern-js/builder-doc@2.18.1
|
18
|
+
|
3
19
|
## 2.18.0
|
4
20
|
|
5
21
|
### Patch Changes
|
File without changes
|
File without changes
|
@@ -9,9 +9,9 @@ sidebar_label: esbuild
|
|
9
9
|
|
10
10
|
## Introduction
|
11
11
|
|
12
|
-
|
12
|
+
import Esbuild from '@modern-js/builder-doc/docs/en/shared/esbuild.md';
|
13
13
|
|
14
|
-
|
14
|
+
<Esbuild />
|
15
15
|
|
16
16
|
:::tip Recommend using SWC
|
17
17
|
We recommend using SWC to transform and minify code rather than esbuild, because SWC supports more syntaxes, provides better code compression, and the compiled code has better compatibility.
|
@@ -20,7 +20,6 @@ Therefore, we recommend that you use SWC instead of esbuild, please refer to [to
|
|
20
20
|
|
21
21
|
:::
|
22
22
|
|
23
|
-
|
24
23
|
## Configuration
|
25
24
|
|
26
25
|
You can set the esbuild compilation behavior through the `tools.esbuild` config.
|
@@ -9,9 +9,9 @@ sidebar_label: swc
|
|
9
9
|
|
10
10
|
## Introduction
|
11
11
|
|
12
|
-
|
12
|
+
import SWC from '@modern-js/builder-doc/docs/en/shared/swc.md';
|
13
13
|
|
14
|
-
|
14
|
+
<SWC />
|
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.
|
@@ -341,6 +341,14 @@ export default async (): Promise<ProfileData> => {
|
|
341
341
|
|
342
342
|
4. When run on the server side, the `loader` functions are packaged into a single bundle, so we do not recommend using `__filename` and `__dirname` for server-side code.
|
343
343
|
|
344
|
+
### FAQ
|
345
|
+
|
346
|
+
1. Relationship between loader and bff functions
|
347
|
+
|
348
|
+
In a CSR project, the loader is executed on the client side and the bff function can be called directly from the loader to make a request.
|
349
|
+
|
350
|
+
In an SSR project, each loader is also a server-side API, and we recommend using loader instead of the BFF function which http method is `get` to avoid one more layer of forwarding and execution.
|
351
|
+
|
344
352
|
## useLoader(Old)
|
345
353
|
|
346
354
|
**`useLoader`** is an API in Modern.js old version. The API is a React Hook specially provided for SSR applications, allowing developers to fetch data in components.
|
@@ -367,6 +367,22 @@ To further improve the user experience and reduce time of loading, Modern.js sup
|
|
367
367
|
- `intent`, the value we recommend for most scenarios, will automatically start loading the corresponding resources and the data defined in the data loader when you mouse over the Link, and will automatically unload it when the mouse is moved away. In our tests, even a direct click can reduce the loading time by about 200ms.
|
368
368
|
- `render`, when the Link component renders, it will load the corresponding resources and the data defined in the data loader.
|
369
369
|
|
370
|
+
#### FAQ
|
371
|
+
|
372
|
+
1. What is the difference between using `render` and not split chunks based on routes?
|
373
|
+
|
374
|
+
- With `render` you can specify which routes are loaded on the first screen, and you can control the rendering so that Link components are rendered only when they are in the visible area.
|
375
|
+
- With `render`, static resources are loaded only when they are idle and do not hog the network with first-screen static resources.
|
376
|
+
- When using server side rendering, data is also prefetched.
|
377
|
+
|
378
|
+
import Motivation from '@site-docs-en/components/convention-routing-movitation'
|
379
|
+
|
380
|
+
<Motivation/>
|
381
|
+
|
382
|
+
import Practice from '@site-docs-en/components/routes-practice'
|
383
|
+
|
384
|
+
<Practice/>
|
385
|
+
|
370
386
|
## Self-controlled routing
|
371
387
|
|
372
388
|
With `src/App.tsx` as the agreed entry, Modern.js will not do additional operations with multiple routes, developers can use the React Router 6 API for development by themselves, for example:
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 4
|
3
|
+
---
|
4
|
+
|
5
|
+
# Glossary
|
6
|
+
|
7
|
+
## BFF
|
8
|
+
|
9
|
+
BFF stands for "Backend For Frontend". It is an architectural pattern where a dedicated backend service is created for frontend applications.
|
10
|
+
|
11
|
+
The BFF service acts as an intermediary between the frontend application and the backend APIs, providing a tailored API for the frontend to consume. This allows the frontend developers to have more control over the data and functionality that they need, without having to rely on a monolithic backend API to provide coresponding capabilities.
|
12
|
+
|
13
|
+
## Bundler
|
14
|
+
|
15
|
+
import Bundler from '@modern-js/builder-doc/docs/en/shared/bundler.md';
|
16
|
+
|
17
|
+
<Bundler />
|
18
|
+
|
19
|
+
## Builder
|
20
|
+
|
21
|
+
import Builder from '@modern-js/builder-doc/docs/en/shared/builder.md';
|
22
|
+
|
23
|
+
<Builder />
|
24
|
+
|
25
|
+
## CSR
|
26
|
+
|
27
|
+
CSR stands for "Client-Side Rendering". It means that pages are rendered directly in the browser using JavaScript. All the logic, data fetching, templating and routing is done on the client rather than the server.
|
28
|
+
|
29
|
+
In CSR, the server sends an empty HTML shell to the client along with some JavaScript bundles, which then fetches data from the server's APIs and populates the page with dynamic content.
|
30
|
+
|
31
|
+
## Garfish
|
32
|
+
|
33
|
+
[Garfish](https://garfish.bytedance.net/) is a set of micro front-end solutions mainly used to solve problems such as cross-team collaboration and technical system diversification of web applications.
|
34
|
+
|
35
|
+
Starting from the architectural level, it integrates several independently delivered front-end applications. These front-end applications can be developed, tested and deployed independently, but from the user's point of view they are still a cohesive single product.
|
36
|
+
|
37
|
+
## Rspack
|
38
|
+
|
39
|
+
import Rspack from '@modern-js/builder-doc/docs/en/shared/rspack.md';
|
40
|
+
|
41
|
+
<Rspack />
|
42
|
+
|
43
|
+
## SSR
|
44
|
+
|
45
|
+
SSR stands for "Server-Side Rendering". It is a technique where the server generates the HTML of a web page and sends it to the client, instead of sending just an empty HTML shell and relying on JavaScript to populate the page.
|
46
|
+
|
47
|
+
In traditional client-side rendering, the server sends an empty HTML shell to the client along with some JavaScript bundles, which then fetches data from the server's APIs and populates the page with dynamic content. This can result in a slower initial load time, which can be detrimental to user experience and SEO.
|
48
|
+
|
49
|
+
With SSR, the server generates the HTML with the dynamic content already populated, and sends it to the client. This can result in a faster initial load time and better SEO, as search engines can crawl the fully rendered page.
|
50
|
+
|
51
|
+
## SSG
|
52
|
+
|
53
|
+
SSG stands for "Static Site Generation". It is a technique where a web page is pre-rendered into static HTML, and then served directly to the client without the need for a server to generate the HTML on the fly.
|
54
|
+
|
55
|
+
In traditional SSR, the server generates the HTML on the fly each time a user requests a page. With SSG, the HTML is generated ahead of time during the build process and can be served directly from a CDN or other static hosting service.
|
56
|
+
|
57
|
+
SSG can provide faster load times and less server overhead to traditional SSR, as there is no need to maintain a server to generate the HTML on the fly. However, it is not suitable for websites that require dynamic content, as the HTML is generated during the build process and cannot be updated in real-time.
|
58
|
+
|
59
|
+
## SWC
|
60
|
+
|
61
|
+
import SWC from '@modern-js/builder-doc/docs/en/shared/swc.md';
|
62
|
+
|
63
|
+
<SWC />
|
@@ -34,7 +34,7 @@ Each option supports two fields:
|
|
34
34
|
|
35
35
|
- label: display name.
|
36
36
|
|
37
|
-
### x-
|
37
|
+
### x-validator
|
38
38
|
|
39
39
|
schema verification rules. Formily's verification method is supported here, for details, please refer to [Formily Validate](https://formilyjs.org/zh-CN/guide/advanced/validate).
|
40
40
|
|
File without changes
|
File without changes
|
@@ -9,9 +9,9 @@ sidebar_label: esbuild
|
|
9
9
|
|
10
10
|
## 介绍
|
11
11
|
|
12
|
-
|
12
|
+
import Esbuild from '@modern-js/builder-doc/docs/zh/shared/esbuild.md';
|
13
13
|
|
14
|
-
|
14
|
+
<Esbuild />
|
15
15
|
|
16
16
|
:::tip 推荐使用 SWC
|
17
17
|
相较于 esbuild,我们更推荐使用 SWC 来编译和压缩代码,因为 SWC 支持更多的语法特性、拥有更好的代码压缩率,并且产物具备更好的兼容性。
|
@@ -9,9 +9,9 @@ sidebar_label: swc
|
|
9
9
|
|
10
10
|
## 介绍
|
11
11
|
|
12
|
-
|
12
|
+
import SWC from '@modern-js/builder-doc/docs/zh/shared/swc.md';
|
13
13
|
|
14
|
-
|
14
|
+
<SWC />
|
15
15
|
|
16
16
|
:::tip
|
17
17
|
在使用 Rspack 作为打包工具时,默认会使用 SWC 进行转译和压缩,因此你不需要再安装和配置 SWC 插件。
|
@@ -339,6 +339,15 @@ export default async (): Promise<ProfileData> => {
|
|
339
339
|
|
340
340
|
4. 在服务端运行时,`loader` 函数会被打包为一个统一的 bundle,所以我们不推荐服务端的代码使用 `__filename` 和 `__dirname`。
|
341
341
|
|
342
|
+
### 常见问题
|
343
|
+
|
344
|
+
1. loader 和 bff 函数的关系
|
345
|
+
|
346
|
+
在 CSR 项目中,loader 在客户端执行,在 loader 可以直接调用 bff 函数进行接口请求。
|
347
|
+
|
348
|
+
在 SSR 项目中,每个 loader 也是一个服务端接口,我们推荐使用 loader 替代 http method 为 `get` 的 BFF 函数,作为接口层,避免多一层转发和执行。
|
349
|
+
|
350
|
+
|
342
351
|
## useLoader(旧版)
|
343
352
|
|
344
353
|
**`useLoader`** 是 Modern.js 老版本中的 API。该 API 是一个 React Hook,专门提供给 SSR 应用使用,让开发者能同构的在组件中获取数据。
|
@@ -444,7 +444,7 @@ export const init = (context: RuntimeContext) => {
|
|
444
444
|
};
|
445
445
|
```
|
446
446
|
|
447
|
-
###
|
447
|
+
### 预加载
|
448
448
|
|
449
449
|
在约定式路由下, Modern.js 会根据路由,自动地对路由进行分片,当用户访问具体的路由时,会自动加载对应的分片,这样可以有效地减少首屏加载的时间。但这也带来了一个问题,当用户访问一个路由时,如果该路由对应的分片还未加载完成,就会出现白屏的情况。
|
450
450
|
这种情况下你可以通过定义 `loading` 组件,在静态资源加载完成前,展示一个自定义的 `loading` 组件。
|
@@ -462,9 +462,24 @@ export const init = (context: RuntimeContext) => {
|
|
462
462
|
:::
|
463
463
|
|
464
464
|
- `none`, 默认值,不会做 prefetch,没有任何额外的行为。
|
465
|
-
- `intent`,这是我们推荐大多数场景下使用的值,当你把鼠标放在 Link 上时,会自动开始加载对应的分片和 data loader
|
465
|
+
- `intent`,这是我们推荐大多数场景下使用的值,当你把鼠标放在 Link 上时,会自动开始加载对应的分片和 data loader 中定义的数据,当鼠标移开时,会自动取消加载。在我们的测试中,即使是快速点击,也能减少大约 200ms 的加载时间。
|
466
466
|
- `render`,当 Link 组件渲染时,就会加载对应的分片和 data loader 中定义的数据。
|
467
467
|
|
468
|
+
#### 常见问题
|
469
|
+
|
470
|
+
1. 使用 `render` 和不根据路由做静态资源分片的区别?
|
471
|
+
|
472
|
+
- 使用 `render` 可以指定哪些路由在首屏时,进行加载,同时你可以通过对渲染的控制,仅当 Link 组件进入到可视区域时,才对 Link 组件进行渲染。
|
473
|
+
- 使用 `render`,仅在空闲时对静态资源进行加载,不会与首屏静态资源抢占网络。
|
474
|
+
- 在 SSR 场景下,也会对数据进行预取。
|
475
|
+
|
476
|
+
import Motivation from '@site-docs/components/convention-routing-movitation'
|
477
|
+
|
478
|
+
<Motivation/>
|
479
|
+
|
480
|
+
import Practice from '@site-docs/components/routes-practice'
|
481
|
+
|
482
|
+
<Practice/>
|
468
483
|
|
469
484
|
|
470
485
|
## 自控式路由
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 4
|
3
|
+
---
|
4
|
+
|
5
|
+
# 名词解释
|
6
|
+
|
7
|
+
## BFF
|
8
|
+
|
9
|
+
BFF 是 "Backend For Frontend"(前端的后端) 的缩写。它是一种架构模式,表示为前端应用程序创建一个专门的后台服务。
|
10
|
+
|
11
|
+
BFF 服务作为前端应用程序和服务端 API 之间的中介,可以为前端提供定制的 API 供其使用。这允许前端开发者对需要的数据和功能有更多的控制,而不必依赖后端服务提供相应的能力。
|
12
|
+
|
13
|
+
## Bundler
|
14
|
+
|
15
|
+
import Bundler from '@modern-js/builder-doc/docs/zh/shared/bundler.md';
|
16
|
+
|
17
|
+
<Bundler />
|
18
|
+
|
19
|
+
## Builder
|
20
|
+
|
21
|
+
import Builder from '@modern-js/builder-doc/docs/zh/shared/builder.md';
|
22
|
+
|
23
|
+
<Builder />
|
24
|
+
|
25
|
+
## CSR
|
26
|
+
|
27
|
+
CSR 是 "Client-Side Rendering"(客户端渲染)的缩写。它表示页面是在浏览器中通过 JavaScript 渲染的,数据获取、模板和路由等逻辑都在浏览器端完成,而不是在服务器上。
|
28
|
+
|
29
|
+
在 CSR 中,服务器会向浏览器端发送一个空的 HTML 外壳和一些 JavaScript 脚本,然后由浏览器端从服务器的 API 中拉取数据,并将动态内容渲染到页面中。
|
30
|
+
|
31
|
+
## Garfish
|
32
|
+
|
33
|
+
[Garfish](https://garfish.bytedance.net/) 是一套微前端解决方案,主要用于解决 web 应用的跨团队协作、技术体系多样化等问题。
|
34
|
+
|
35
|
+
它从架构层面出发,将多个独立交付的前端应用组成整体,这些前端应用能够独立开发、独立测试、独立部署,但是在用户视角仍然是内聚的单个产品。
|
36
|
+
|
37
|
+
## Rspack
|
38
|
+
|
39
|
+
import Rspack from '@modern-js/builder-doc/docs/zh/shared/rspack.md';
|
40
|
+
|
41
|
+
<Rspack />
|
42
|
+
|
43
|
+
## SSR
|
44
|
+
|
45
|
+
SSR 是 "Server-Side Rendering"(服务器端渲染)的缩写。它表示由服务器生成网页的 HTML,并将其发送给客户端,而不是只发送一个空的 HTML 外壳,并依赖 JavaScript 来生成页面内容。
|
46
|
+
|
47
|
+
在传统的客户端渲染中,服务器会向客户端发送一个空的 HTML 外壳和一些 JavaScript 脚本,然后从服务器的 API 中获取数据,并用动态内容填充页面。这会导致页面的初始加载时间较慢,不利于用户体验和 SEO。
|
48
|
+
|
49
|
+
使用 SSR 后,服务器会生成已经包含动态内容的 HTML,并将其发送给客户端。这使得首屏加载速度更快,并对 SEO 更加友好,因为搜索引擎可以爬取到渲染后的页面。
|
50
|
+
|
51
|
+
## SSG
|
52
|
+
|
53
|
+
SSG 是 "Static Site Generation"(静态网站生成)的缩写。它表示网页被预先渲染成静态的 HTML,然后直接提供给客户端,而不需要服务器实时生成 HTML。
|
54
|
+
|
55
|
+
在传统的 SSR 中,每当用户请求一个页面时,服务器就会实时生成 HTML。有了 SSG,HTML 可以在构建过程中被提前生成,并被托管在 CDN 或其他静态资源服务中。
|
56
|
+
|
57
|
+
与传统的 SSR 相比,SSG 可以提供更快的加载速度以及更少的服务端开销,因为不需要维护一个服务器来实时生成 HTML。然而,SSG 不适合需要动态内容的网站,因为 HTML 是在构建过程中生成的,不支持实时更新。
|
58
|
+
|
59
|
+
## SWC
|
60
|
+
|
61
|
+
import SWC from '@modern-js/builder-doc/docs/zh/shared/swc.md';
|
62
|
+
|
63
|
+
<SWC />
|
package/package.json
CHANGED
@@ -15,13 +15,13 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.19.0",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public"
|
22
22
|
},
|
23
23
|
"peerDependencies": {
|
24
|
-
"@modern-js/builder-doc": "^2.
|
24
|
+
"@modern-js/builder-doc": "^2.19.0"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"classnames": "^2",
|
@@ -33,9 +33,9 @@
|
|
33
33
|
"fs-extra": "^10",
|
34
34
|
"@types/node": "^16",
|
35
35
|
"@types/fs-extra": "^9",
|
36
|
-
"@modern-js/builder-doc": "2.
|
37
|
-
"@modern-js/doc-tools": "2.
|
38
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.
|
36
|
+
"@modern-js/builder-doc": "2.19.0",
|
37
|
+
"@modern-js/doc-tools": "2.19.0",
|
38
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.19.0"
|
39
39
|
},
|
40
40
|
"scripts": {
|
41
41
|
"dev": "modern dev",
|