@modern-js/main-doc 0.0.0-nightly-20240123170645 → 0.0.0-nightly-20240124170638
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/commands.mdx +9 -9
- package/docs/en/configure/app/builder-plugins.mdx +13 -13
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +1 -1
- package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
- package/docs/en/guides/advanced-features/optimize-bundle.mdx +7 -7
- package/docs/en/guides/advanced-features/rspack-start.mdx +0 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +7 -21
- package/docs/en/guides/get-started/tech-stack.mdx +1 -1
- package/docs/zh/apis/app/commands.mdx +9 -9
- package/docs/zh/configure/app/builder-plugins.mdx +14 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +1 -1
- package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
- package/docs/zh/guides/advanced-features/optimize-bundle.mdx +8 -8
- package/docs/zh/guides/basic-features/css.mdx +2 -2
- package/docs/zh/guides/concept/builder.mdx +7 -21
- package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
- package/package.json +5 -5
@@ -195,7 +195,7 @@ Options:
|
|
195
195
|
|
196
196
|
## modern inspect
|
197
197
|
|
198
|
-
The `modern inspect` command is used to view the [
|
198
|
+
The `modern inspect` command is used to view the [Rsbuild config](https://rsbuild.dev/config/index) and webpack or Rspack config of the project.
|
199
199
|
|
200
200
|
```bash
|
201
201
|
Usage: modern inspect [options]
|
@@ -210,16 +210,16 @@ Options:
|
|
210
210
|
|
211
211
|
After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:
|
212
212
|
|
213
|
-
- `
|
214
|
-
- `webpack.config.web.
|
213
|
+
- `rsbuild.config.mjs`: The Rsbuild config to use at build time.
|
214
|
+
- `webpack.config.web.mjs`: The webpack config used by to use at build time.
|
215
215
|
|
216
216
|
```bash
|
217
217
|
➜ npx modern inspect
|
218
218
|
|
219
219
|
Inspect config succeed, open following files to view the content:
|
220
220
|
|
221
|
-
-
|
222
|
-
- Webpack Config (web): /root/my-project/dist/webpack.config.web.
|
221
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
222
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
|
223
223
|
```
|
224
224
|
|
225
225
|
### Configuration Env
|
@@ -240,16 +240,16 @@ modern inspect --verbose
|
|
240
240
|
|
241
241
|
### SSR Configuration
|
242
242
|
|
243
|
-
If the project has enabled SSR, an additional `webpack.config.node.
|
243
|
+
If the project has enabled SSR, an additional `webpack.config.node.mjs` file will be generated in the `dist/`, corresponding to the webpack configuration at SSR build time.
|
244
244
|
|
245
245
|
```bash
|
246
246
|
➜ npx modern inspect
|
247
247
|
|
248
248
|
Inspect config succeed, open following files to view the content:
|
249
249
|
|
250
|
-
-
|
251
|
-
- Webpack Config (web): /root/my-project/dist/webpack.config.web.
|
252
|
-
- Webpack Config (node): /root/my-project/dist/webpack.config.node.
|
250
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
251
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
|
252
|
+
- Webpack Config (node): /root/my-project/dist/webpack.config.node.mjs
|
253
253
|
```
|
254
254
|
|
255
255
|
## modern lint
|
@@ -4,16 +4,16 @@ sidebar_position: 21
|
|
4
4
|
|
5
5
|
# builderPlugins
|
6
6
|
|
7
|
-
- **Type:** `
|
7
|
+
- **Type:** `RsbuildPlugin[]`
|
8
8
|
- **Default:** `[]`
|
9
9
|
|
10
|
-
Used to configure the
|
10
|
+
Used to configure the Rsbuild plugin.
|
11
11
|
|
12
|
-
|
12
|
+
Rsbuild is the build tool of Modern.js, please read [Build Engine](/guides/concept/builder) for background. If you want to know how to write Rsbuild plugins, you can refer to [Rsbuild - Plugin System](https://rsbuild.dev/plugins/dev/index).
|
13
13
|
|
14
14
|
## Precautions
|
15
15
|
|
16
|
-
This option **is used to configure the
|
16
|
+
This option **is used to configure the Rsbuild plugins**. If you need to configure other types of plugins, please select the corresponding configs:
|
17
17
|
|
18
18
|
- Use [plugins](/configure/app/plugins) to configure Modern.js framework plugins.
|
19
19
|
- Use [tools.bundlerChain](/configure/app/tools/bundler-chain) to configure Rspack or webpack plugins.
|
@@ -21,23 +21,23 @@ This option **is used to configure the Modern.js Builder plugins**. If you need
|
|
21
21
|
|
22
22
|
## When to use
|
23
23
|
|
24
|
-
In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the
|
24
|
+
In most scenarios, we recommend you to use the Modern.js framework plugin, which can be registered through the [plugins](/configure/app/plugins) config. Because the API provided by the framework plugin is richer and more capable, while the API provided by the Rsbuild plugin can only be used to build scenes.
|
25
25
|
|
26
|
-
When you need to reference some existing
|
26
|
+
When you need to reference some existing Rsbuild plugins (and there is no related capability in Modern.js), or reuse Rsbuild plugins between different frameworks, you can use the `builderPlugins` field to register them.
|
27
27
|
|
28
28
|
## Example
|
29
29
|
|
30
|
-
Below is an example of using the
|
30
|
+
Below is an example of using the Rsbuild plugin.
|
31
31
|
|
32
32
|
### Using plugins on npm
|
33
33
|
|
34
34
|
To use a plugin on npm, you need to install the plugin through the package manager and import it.
|
35
35
|
|
36
36
|
```ts title="modern.config.ts"
|
37
|
-
import
|
37
|
+
import myRsbuildPlugin from 'my-rsbuild-plugin';
|
38
38
|
|
39
39
|
export default defineConfig({
|
40
|
-
builderPlugins: [
|
40
|
+
builderPlugins: [myRsbuildPlugin()],
|
41
41
|
});
|
42
42
|
```
|
43
43
|
|
@@ -46,10 +46,10 @@ export default defineConfig({
|
|
46
46
|
Use the plugin in the local code repository, you can import it directly through the relative path import.
|
47
47
|
|
48
48
|
```ts title="modern.config.ts"
|
49
|
-
import
|
49
|
+
import myRsbuildPlugin from './plugin/myRsbuildPlugin';
|
50
50
|
|
51
51
|
export default defineConfig({
|
52
|
-
builderPlugins: [
|
52
|
+
builderPlugins: [myRsbuildPlugin()],
|
53
53
|
});
|
54
54
|
```
|
55
55
|
|
@@ -58,11 +58,11 @@ export default defineConfig({
|
|
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
|
|
60
60
|
```ts title="modern.config.ts"
|
61
|
-
import
|
61
|
+
import myRsbuildPlugin from 'my-rsbuild-plugin';
|
62
62
|
|
63
63
|
export default defineConfig({
|
64
64
|
builderPlugins: [
|
65
|
-
|
65
|
+
myRsbuildPlugin({
|
66
66
|
foo: 1,
|
67
67
|
bar: 2,
|
68
68
|
}),
|
@@ -19,4 +19,4 @@ export default defineConfig({
|
|
19
19
|
});
|
20
20
|
```
|
21
21
|
|
22
|
-
This config is implemented based on the Node Polyfill plugin of
|
22
|
+
This config is implemented based on the Node Polyfill plugin of Rsbuild, you can read [Rsbuild - Node Polyfill Plugin](https://rsbuild.dev/plugins/list/plugin-node-polyfill) documentation for details.
|
@@ -19,7 +19,7 @@ ios_saf >= 10
|
|
19
19
|
```
|
20
20
|
|
21
21
|
:::tip
|
22
|
-
Please refer to [
|
22
|
+
Please refer to [Rsbuild - Browserslist](https://rsbuild.dev/guide/advanced/browserslist) for more information.
|
23
23
|
:::
|
24
24
|
|
25
25
|
## Polyfill
|
@@ -4,7 +4,7 @@ sidebar_position: 13
|
|
4
4
|
|
5
5
|
# Bundle Size Optimization
|
6
6
|
|
7
|
-
Bundle size optimization is an important part in production environment because it directly affects the user experience of online users. In this document, we will introduce some common bundle size optimization methods in
|
7
|
+
Bundle size optimization is an important part in production environment because it directly affects the user experience of online users. In this document, we will introduce some common bundle size optimization methods in Modern.js.
|
8
8
|
|
9
9
|
## Reduce duplicate dependencies
|
10
10
|
|
@@ -59,7 +59,7 @@ For example, if you only need to be compatible with browsers above Chrome 61, yo
|
|
59
59
|
```
|
60
60
|
|
61
61
|
:::tip
|
62
|
-
Please read the [Browserslist](https://
|
62
|
+
Please read the [Browserslist](https://rsbuild.dev/guide/advanced/browserslist) chapter to know more about the usage of Browserslist.
|
63
63
|
:::
|
64
64
|
|
65
65
|
## Usage polyfill
|
@@ -82,23 +82,23 @@ Please read the [Browser Compatibility](/guides/advanced-features/compatibility)
|
|
82
82
|
|
83
83
|
## Image Compression
|
84
84
|
|
85
|
-
In general front-end projects, the size of image often accounts for a large proportion of the total bundle size of the project.So if the image size can be reduced as much as possible, it will have a significant optimization effect on the project bundle size. You can enable image compression by registering a plugin in
|
85
|
+
In general front-end projects, the size of image often accounts for a large proportion of the total bundle size of the project.So if the image size can be reduced as much as possible, it will have a significant optimization effect on the project bundle size. You can enable image compression by registering a plugin in Modern.js:
|
86
86
|
|
87
87
|
```ts title="modern.config.ts"
|
88
|
-
import {
|
88
|
+
import { pluginImageCompress } from '@rsbuild/plugin-image-compress';
|
89
89
|
|
90
90
|
export default {
|
91
|
-
builderPlugins: [
|
91
|
+
builderPlugins: [pluginImageCompress()],
|
92
92
|
};
|
93
93
|
```
|
94
94
|
|
95
|
-
See details in [plugin-image-compress](https://
|
95
|
+
See details in [plugin-image-compress](https://rsbuild.dev/plugins/list/plugin-image-compress).
|
96
96
|
|
97
97
|
## Split Chunk
|
98
98
|
|
99
99
|
A great chunk splitting strategy is very important to improve the loading performance of the application. It can make full use of the browser's caching mechanism to reduce the number of requests and improve the loading speed of the application.
|
100
100
|
|
101
|
-
A variety of [chunk splitting strategies](https://
|
101
|
+
A variety of [chunk splitting strategies](https://rsbuild.dev/guide/optimization/split-chunk) are built into Modern.js, which can meet the needs of most applications. You can also customize the chunk splitting config according to your own business scenarios.
|
102
102
|
|
103
103
|
For example, split the `axios` library under node_modules into `axios.js`:
|
104
104
|
|
@@ -55,8 +55,6 @@ import RspackPrecautions from '@modern-js/builder-doc/docs/en/shared/rspackPreca
|
|
55
55
|
|
56
56
|
## Migrating configuration
|
57
57
|
|
58
|
-
After enabling Rspack building capability, further configuration migration is needed by referring to the [Configuration Differences](https://modernjs.dev/builder/en/guide/advanced/rspack-start.html#migrating-from-webpack-to-rspack).
|
59
|
-
|
60
58
|
In Modern.js, the [tools.webpack](/configure/app/tools/webpack) and [tools.webpackChain](/configure/app/tools/webpack-chain) configurations only take effect in webpack mode, after turning on the Rspack build, you can modify it to [tools.rspack](/configure/app/tools/rspack) and [tools.bundlerChain](/configure/app/tools/bundler-chain).
|
61
59
|
|
62
60
|
```diff
|
@@ -12,13 +12,13 @@ Modern.js has built-in popular community CSS preprocessors, including Less and S
|
|
12
12
|
|
13
13
|
By default, you don't need to configure Less and Sass. If you have custom loader configuration requirements, you can set them up by configuring [tools.less](/configure/app/tools/less) and [tools.sass](/configure/app/tools/sass).
|
14
14
|
|
15
|
-
You can also use Stylus in Modern.js by installing the Stylus plugin provided by
|
15
|
+
You can also use Stylus in Modern.js by installing the Stylus plugin provided by Rsbuild. For usage, please refer to [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus).
|
16
16
|
|
17
17
|
## Using PostCSS
|
18
18
|
|
19
19
|
Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
|
20
20
|
|
21
|
-
Please refer to [
|
21
|
+
Please refer to [Rsbuild - Using PostCSS](https://rsbuild.dev/guide/basic/css-usage#using-postcss) for detailed usage.
|
22
22
|
|
23
23
|
## Using CSS Modules
|
24
24
|
|
@@ -4,9 +4,9 @@ sidebar_position: 2
|
|
4
4
|
|
5
5
|
# Build Engine
|
6
6
|
|
7
|
-
|
7
|
+
Modern.js Builder refers to the build layer of Modern.js. Its goal is to provide Modern.js users with out-of-the-box build capabilities and support seamless switching between webpack and Rspack.
|
8
8
|
|
9
|
-
Modern.js Builder is
|
9
|
+
Modern.js Builder is based on [Rsbuild](https://rsbuild.dev/). Rsbuild is a build tool for web development scenarios that can be used independently of Modern.js.
|
10
10
|
|
11
11
|
## Build Architecture
|
12
12
|
|
@@ -20,28 +20,14 @@ From a building perspective, Modern.js is divided into three layers, from top to
|
|
20
20
|
|
21
21
|
## Builder Documentation
|
22
22
|
|
23
|
-
|
23
|
+
The documentation address of Rsbuild is: https://rsbuild.dev/
|
24
24
|
|
25
|
-
In this documentation, you can learn about the detailed introduction of
|
25
|
+
In this documentation, you can learn about the detailed introduction of Rsbuild, and you can also find complete usage guides for various building capabilities.
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
Modern.js's configuration inherits from Modern.js Builder, so you can use all the build configurations provided by Modern.js Builder in Modern.js.
|
30
|
-
|
31
|
-
Taking the `html.title` config option of Modern.js Builder as an example, you can directly use this option in the `modern.config.ts` file, and it will be automatically passed to Modern.js Builder.
|
32
|
-
|
33
|
-
```ts title="modern.config.js"
|
34
|
-
export default defineConfig({
|
35
|
-
html: {
|
36
|
-
title: 'example',
|
37
|
-
},
|
38
|
-
});
|
39
|
-
```
|
40
|
-
|
41
|
-
For detailed information about build configuration, please refer to [「Modern.js Builder - Builder Config」](https://modernjs.dev/builder/en/guide/basic/builder-config.html).
|
27
|
+
If you want to understand the use of build configurations, it is recommended that you read the Modern.js documentation first, because the build configurations and defaults in Modern.js are not exactly the same as Rsbuild.
|
42
28
|
|
43
29
|
## Builder Capabilities
|
44
30
|
|
45
|
-
|
31
|
+
Rsbuild provides rich build capabilities, including JavaScript compilation, CSS compilation, static assets processing, code hot update, code compression, TS type checking, and dozens of other capabilities.
|
46
32
|
|
47
|
-
We recommend that you read [「
|
33
|
+
We recommend that you read [「Rsbuild - All Features」](https://rsbuild.dev/guide/start/features) to learn about all the features provided by Rsbuild.
|
@@ -89,7 +89,7 @@ Modern.js supports enabling ["Tailwind CSS"](/en/guides/basic-features/css.html#
|
|
89
89
|
Modern.js supports three CSS preprocessors: [Sass](https://sass-lang.com/), [Less](https://lesscss.org/), and [Stylus](https://stylus-lang.com/):
|
90
90
|
|
91
91
|
- Sass and Less are supported by default and ready to use.
|
92
|
-
- Stylus is optional and can be used by referring to the ["Stylus Plugin"](https://
|
92
|
+
- Stylus is optional and can be used by referring to the ["Stylus Plugin"](https://rsbuild.dev/plugins/list/plugin-stylus).
|
93
93
|
|
94
94
|
---
|
95
95
|
|
@@ -195,7 +195,7 @@ Options:
|
|
195
195
|
|
196
196
|
## modern inspect
|
197
197
|
|
198
|
-
`modern inspect` 命令用于查看项目的 [
|
198
|
+
`modern inspect` 命令用于查看项目的 [Rsbuild 配置](https://rsbuild.dev/zh/config/index) 以及 webpack 或 Rspack 配置。
|
199
199
|
|
200
200
|
```bash
|
201
201
|
Usage: modern inspect [options]
|
@@ -210,16 +210,16 @@ Options:
|
|
210
210
|
|
211
211
|
在项目根目录下执行命令 `npx modern inspect` 后,会在项目的 `dist` 目录生成以下文件:
|
212
212
|
|
213
|
-
- `
|
214
|
-
- `webpack.config.web.
|
213
|
+
- `rsbuild.config.mjs`: 表示在构建时使用的 Rsbuild 配置。
|
214
|
+
- `webpack.config.web.mjs`: 表示在构建时使用的 webpack 配置。
|
215
215
|
|
216
216
|
```bash
|
217
217
|
➜ npx modern inspect
|
218
218
|
|
219
219
|
Inspect config succeed, open following files to view the content:
|
220
220
|
|
221
|
-
-
|
222
|
-
- Webpack Config (web): /root/my-project/dist/webpack.config.web.
|
221
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
222
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
|
223
223
|
```
|
224
224
|
|
225
225
|
### 指定环境
|
@@ -240,16 +240,16 @@ modern inspect --verbose
|
|
240
240
|
|
241
241
|
### SSR 构建配置
|
242
242
|
|
243
|
-
如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.config.node.
|
243
|
+
如果项目开启了 SSR 能力,则在 `dist` 目录会另外生成一份 `webpack.config.node.mjs` 文件,对应 SSR 构建时的 webpack 配置。
|
244
244
|
|
245
245
|
```bash
|
246
246
|
➜ npx modern inspect
|
247
247
|
|
248
248
|
Inspect config succeed, open following files to view the content:
|
249
249
|
|
250
|
-
-
|
251
|
-
- Webpack Config (web): /root/my-project/dist/webpack.config.web.
|
252
|
-
- Webpack Config (node): /root/my-project/dist/webpack.config.node.
|
250
|
+
- Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
|
251
|
+
- Webpack Config (web): /root/my-project/dist/webpack.config.web.mjs
|
252
|
+
- Webpack Config (node): /root/my-project/dist/webpack.config.node.mjs
|
253
253
|
```
|
254
254
|
|
255
255
|
## modern lint
|
@@ -4,18 +4,18 @@ sidebar_position: 21
|
|
4
4
|
|
5
5
|
# builderPlugins 构建插件
|
6
6
|
|
7
|
-
- **类型:** `
|
7
|
+
- **类型:** `RsbuildPlugin[]`
|
8
8
|
- **默认值:** `[]`
|
9
9
|
|
10
|
-
用于配置
|
10
|
+
用于配置 Rsbuild 构建插件。
|
11
11
|
|
12
|
-
|
12
|
+
Rsbuild 是 Modern.js 底层的构建工具,请阅读 [构建能力](/guides/concept/builder) 了解相关背景。
|
13
13
|
|
14
|
-
如果你想了解
|
14
|
+
如果你想了解 Rsbuild 插件的编写方式,可以参考 [Rsbuild - 插件系统](https://rsbuild.dev/zh/plugins/dev/index)。
|
15
15
|
|
16
16
|
## 注意事项
|
17
17
|
|
18
|
-
该选项**用于配置
|
18
|
+
该选项**用于配置 Rsbuild 构建插件**,如果你需要配置其他类型的插件,请选择对应的配置方式:
|
19
19
|
|
20
20
|
- 配置 Modern.js 框架插件,请使用 [plugins](/configure/app/plugins) 配置项。
|
21
21
|
- 配置 Rspack 或 webpack 插件,请使用 [tools.bundlerChain](/configure/app/tools/bundler-chain) 配置项。
|
@@ -23,23 +23,23 @@ Modern.js Builder 是 Modern.js 底层的构建工具,请阅读 [构建能力]
|
|
23
23
|
|
24
24
|
## 何时使用
|
25
25
|
|
26
|
-
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](/configure/app/plugins) 字段进行注册。因为框架插件提供的 API 更丰富、能力更强,而
|
26
|
+
大部分场景下,我们推荐你使用 Modern.js 框架插件,框架插件可以通过 [plugins](/configure/app/plugins) 字段进行注册。因为框架插件提供的 API 更丰富、能力更强,而 Rsbuild 插件提供的 API 只能用于构建场景。
|
27
27
|
|
28
|
-
当你需要引用一些现有的
|
28
|
+
当你需要引用一些现有的 Rsbuild 插件(并且在 Modern.js 中没有相关能力),或是在不同的框架之间复用 Rsbuild 插件时,你可以使用 `builderPlugins` 字段进行注册。
|
29
29
|
|
30
30
|
## 示例
|
31
31
|
|
32
|
-
下面是
|
32
|
+
下面是 Rsbuild 插件的使用示例。
|
33
33
|
|
34
34
|
### 使用 npm 上的插件
|
35
35
|
|
36
36
|
使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。
|
37
37
|
|
38
38
|
```ts title="modern.config.ts"
|
39
|
-
import {
|
39
|
+
import { myRsbuildPlugin } from 'my-rsbuild-plugin';
|
40
40
|
|
41
41
|
export default defineConfig({
|
42
|
-
builderPlugins: [
|
42
|
+
builderPlugins: [myRsbuildPlugin()],
|
43
43
|
});
|
44
44
|
```
|
45
45
|
|
@@ -48,10 +48,10 @@ export default defineConfig({
|
|
48
48
|
使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。
|
49
49
|
|
50
50
|
```ts title="modern.config.ts"
|
51
|
-
import {
|
51
|
+
import { myRsbuildPlugin } from './plugin/myRsbuildPlugin';
|
52
52
|
|
53
53
|
export default defineConfig({
|
54
|
-
builderPlugins: [
|
54
|
+
builderPlugins: [myRsbuildPlugin()],
|
55
55
|
});
|
56
56
|
```
|
57
57
|
|
@@ -60,11 +60,11 @@ export default defineConfig({
|
|
60
60
|
如果插件提供了一些自定义的配置项,可以通过插件函数的参数传入配置。
|
61
61
|
|
62
62
|
```ts title="modern.config.ts"
|
63
|
-
import {
|
63
|
+
import { myRsbuildPlugin } from 'my-rsbuild-plugin';
|
64
64
|
|
65
65
|
export default defineConfig({
|
66
66
|
builderPlugins: [
|
67
|
-
|
67
|
+
myRsbuildPlugin({
|
68
68
|
foo: 1,
|
69
69
|
bar: 2,
|
70
70
|
}),
|
@@ -19,4 +19,4 @@ export default defineConfig({
|
|
19
19
|
});
|
20
20
|
```
|
21
21
|
|
22
|
-
该配置项基于
|
22
|
+
该配置项基于 Rsbuild 的 Node Polyfill 插件实现,你可以阅读 [Rsbuild - Node Polyfill 插件](https://rsbuild.dev/zh/plugins/list/plugin-node-polyfill) 文档来了解详细信息。
|
@@ -44,9 +44,9 @@ BUNDLE_ANALYZE=true pnpm build
|
|
44
44
|
|
45
45
|
## 提升 Browserslist 范围
|
46
46
|
|
47
|
-
|
47
|
+
Modern.js 会根据项目的 Browserslist 配置范围进行代码编译,并注入相应的 Polyfill。如果项目不需要兼容旧版浏览器,可以根据实际情况来提升 Browserslist 范围,从而减少在语法和 Polyfill 上的编译开销。
|
48
48
|
|
49
|
-
|
49
|
+
Modern.js 默认的 Browserslist 配置为:
|
50
50
|
|
51
51
|
```js
|
52
52
|
['> 0.01%', 'not dead', 'not op_mini all'];
|
@@ -59,14 +59,14 @@ Builder 默认的 Browserslist 配置为:
|
|
59
59
|
```
|
60
60
|
|
61
61
|
:::tip
|
62
|
-
请阅读 [设置浏览器范围](https://
|
62
|
+
请阅读 [设置浏览器范围](https://rsbuild.dev/zh/guide/advanced/browserslist) 章节来了解更多关于 Browserslist 的用法。
|
63
63
|
:::
|
64
64
|
|
65
65
|
## 按需引入 polyfill
|
66
66
|
|
67
67
|
在明确第三方依赖不需要额外 polyfill 的情况下,你可以将 [output.polyfill](/configure/app/output/polyfill.html) 设置为 `usage`。
|
68
68
|
|
69
|
-
在 `usage` 模式下,
|
69
|
+
在 `usage` 模式下,Modern.js 会分析源代码中使用的语法,按需注入所需的 polyfill 代码,从而减少 polyfill 的代码量。
|
70
70
|
|
71
71
|
```js
|
72
72
|
export default {
|
@@ -85,20 +85,20 @@ export default {
|
|
85
85
|
在一般的前端项目中,图片资源的体积往往是项目产物体积的大头,因此如果能尽可能精简图片的体积,那么将会对项目的打包产物体积起到明显的优化效果。你可以在 Modern.js 中注册插件来启用图片压缩功能:
|
86
86
|
|
87
87
|
```js title="modern.config.ts"
|
88
|
-
import {
|
88
|
+
import { pluginImageCompress } from '@rsbuild/plugin-image-compress';
|
89
89
|
|
90
90
|
export default {
|
91
|
-
builderPlugins: [
|
91
|
+
builderPlugins: [pluginImageCompress()],
|
92
92
|
};
|
93
93
|
```
|
94
94
|
|
95
|
-
详见 [Image Compress 插件](https://
|
95
|
+
详见 [Image Compress 插件](https://rsbuild.dev/zh/plugins/list/plugin-image-compress)。
|
96
96
|
|
97
97
|
## 代码拆包
|
98
98
|
|
99
99
|
良好的拆包策略对于提升应用的加载性能是十分重要的,可以充分利用浏览器的缓存机制,减少请求数量,加快页面加载速度。
|
100
100
|
|
101
|
-
在 Modern.js 中内置了[多种拆包策略](https://
|
101
|
+
在 Modern.js 中内置了[多种拆包策略](https://rsbuild.dev/zh/guide/optimization/split-chunk),可以满足大部分应用的需求,你也可以根据自己的业务场景,自定义拆包配置。
|
102
102
|
|
103
103
|
比如将 node_modules 下的 `axios` 库拆分到 `axios.js` 中:
|
104
104
|
|
@@ -12,13 +12,13 @@ Modern.js 内置了社区流行的 CSS 预处理器,包括 Less 和 Sass。
|
|
12
12
|
|
13
13
|
默认情况下,你不需要对 Less 和 Sass 进行任何配置。如果你有自定义 loader 配置的需求,可以通过配置 [tools.less](/configure/app/tools/less)、[tools.sass](/configure/app/tools/sass) 来进行设置。
|
14
14
|
|
15
|
-
你也可以在 Modern.js 中使用 Stylus,只需要安装
|
15
|
+
你也可以在 Modern.js 中使用 Stylus,只需要安装 Rsbuild 提供的 Stylus 插件即可,使用方式请参考 [Stylus 插件](https://rsbuild.dev/zh/plugins/list/plugin-stylus)。
|
16
16
|
|
17
17
|
## 使用 PostCSS
|
18
18
|
|
19
19
|
Modern.js 内置了 [PostCSS](https://postcss.org/) 来转换 CSS 代码。
|
20
20
|
|
21
|
-
请阅读 [
|
21
|
+
请阅读 [Rsbuild - 使用 PostCSS](https://rsbuild.dev/zh/guide/basic/css-usage#%E4%BD%BF%E7%94%A8-postcss) 了解更多用法。
|
22
22
|
|
23
23
|
## 使用 CSS Modules
|
24
24
|
|
@@ -4,9 +4,9 @@ sidebar_position: 2
|
|
4
4
|
|
5
5
|
# 构建工具
|
6
6
|
|
7
|
-
|
7
|
+
Modern.js Builder 指的是 Modern.js 的构建层,它的目标是为 Modern.js 用户提供开箱即用的构建能力,并支持在 webpack 和 Rspack 间无缝切换。
|
8
8
|
|
9
|
-
Modern.js Builder
|
9
|
+
Modern.js Builder 基于 [Rsbuild](https://rsbuild.dev/) 封装。Rsbuild 是一个基于 Rspack 的 Web 构建工具,可以脱离 Modern.js 被独立使用。
|
10
10
|
|
11
11
|
## 构建架构
|
12
12
|
|
@@ -20,28 +20,14 @@ Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个基于
|
|
20
20
|
|
21
21
|
## 构建文档
|
22
22
|
|
23
|
-
|
23
|
+
Rsbuild 的文档地址为:https://rsbuild.dev/
|
24
24
|
|
25
|
-
在该文档中,你可以了解到
|
25
|
+
在该文档中,你可以了解到 Rsbuild 的详细介绍,同时也可以找到各个构建能力的完整使用指南。
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
Modern.js 的配置继承自 Modern.js Builder,因此你可以在 Modern.js 中使用 Modern.js Builder 提供的所有构建配置。
|
30
|
-
|
31
|
-
以 Modern.js Builder 的 `html.title` 配置项为例,你可以直接在 `modern.config.ts` 文件中使用该配置项,它会被自动传递给 Modern.js Builder。
|
32
|
-
|
33
|
-
```ts title="modern.config.js"
|
34
|
-
export default defineConfig({
|
35
|
-
html: {
|
36
|
-
title: 'example',
|
37
|
-
},
|
38
|
-
});
|
39
|
-
```
|
40
|
-
|
41
|
-
关于构建配置的详细说明,请参考 [「Modern.js Builder - Builder 配置」](https://modernjs.dev/builder/guide/basic/builder-config.html)。
|
27
|
+
如果你想要了解某些构建配置的使用,建议你优先阅读 Modern.js 文档,因为 Modern.js 中的构建配置和默认值与 Rsbuild 并不完全相同。
|
42
28
|
|
43
29
|
## 构建能力
|
44
30
|
|
45
|
-
|
31
|
+
Rsbuild 提供了丰富的构建能力,包括 JavaScript 编译、CSS 编译、静态资源处理、代码热更新、代码压缩、TS 类型检查等几十种能力。
|
46
32
|
|
47
|
-
我们推荐你阅读 [「
|
33
|
+
我们推荐你阅读 [「Rsbuild - 功能导航」](https://rsbuild.dev/zh/guide/start/features) 来了解 Rsbuild 提供的所有构建能力。
|
@@ -89,7 +89,7 @@ Modern.js 支持[「启用 Tailwind CSS」](/guides/basic-features/css.html#使
|
|
89
89
|
Modern.js 支持 [Sass](https://sass-lang.com/)、[Less](https://lesscss.org/) 和 [Stylus](https://stylus-lang.com/) 三种 CSS 预处理器:
|
90
90
|
|
91
91
|
- 默认支持 Sass 和 Less,开箱即用。
|
92
|
-
- 可选支持 Stylus,请参考[「Stylus 插件」](https://
|
92
|
+
- 可选支持 Stylus,请参考[「Stylus 插件」](https://rsbuild.dev/zh/plugins/list/plugin-stylus) 来使用。
|
93
93
|
|
94
94
|
---
|
95
95
|
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "0.0.0-nightly-
|
18
|
+
"version": "0.0.0-nightly-20240124170638",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "0.0.0-nightly-
|
25
|
+
"@modern-js/sandpack-react": "0.0.0-nightly-20240124170638"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "0.0.0-nightly-
|
28
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240124170638"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -39,8 +39,8 @@
|
|
39
39
|
"@rspress/shared": "1.10.1",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "9.0.13",
|
42
|
-
"@modern-js/
|
43
|
-
"@modern-js/doc
|
42
|
+
"@modern-js/doc-plugin-auto-sidebar": "0.0.0-nightly-20240124170638",
|
43
|
+
"@modern-js/builder-doc": "0.0.0-nightly-20240124170638"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|