@rsdoctor/docs 0.0.1 → 0.1.9-beta.1
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/LICENSE +21 -0
- package/docs/en/config/options/options-shared.mdx +67 -0
- package/docs/en/config/options/options.mdx +44 -8
- package/docs/en/guide/start/quick-start-shared.mdx +184 -0
- package/docs/en/guide/start/quick-start.mdx +2 -183
- package/docs/en/guide/usage/plugins-analysis.mdx +2 -2
- package/docs/en/guide/usage/project-overall.mdx +2 -2
- package/docs/zh/config/options/options-shared.mdx +70 -0
- package/docs/zh/guide/start/quick-start-shared.mdx +183 -0
- package/docs/zh/guide/start/quick-start.mdx +2 -182
- package/docs/zh/guide/usage/plugins-analysis.mdx +2 -2
- package/docs/zh/guide/usage/project-overall.mdx +2 -2
- package/package.json +12 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
## Options
|
|
2
|
+
|
|
3
|
+
**Type:** `Object`
|
|
4
|
+
|
|
5
|
+
This is the options for the [RsdoctorWebpackPlugin](#rsdoctorwebpackplugin) and [RsdoctorRspackPlugin](#rsdoctorrspackplugin). It contains these properties:
|
|
6
|
+
|
|
7
|
+
- [disableClientServer](#disableclientserver)
|
|
8
|
+
- [features](#features)
|
|
9
|
+
|
|
10
|
+
### disableClientServer
|
|
11
|
+
|
|
12
|
+
- **Type:** `boolean`
|
|
13
|
+
- **Optional:** `true`
|
|
14
|
+
- **Default:** `false`
|
|
15
|
+
|
|
16
|
+
Whether to automatically open the Rsdoctor report page. If you do not need to view the analysis report provided by Rsdoctor in the browser, you can enable this configuration item.
|
|
17
|
+
|
|
18
|
+
### features
|
|
19
|
+
|
|
20
|
+
- **Type:** [RsdoctorWebpackPluginFeatures](#rsdoctorwebpackpluginfeatures) | [Array\<keyof RsdoctorWebpackPluginFeatures\>](#rsdoctorwebpackpluginfeatures) | [RsdoctorRspackPluginFeatures](#rsdoctorrspackpluginfeatures) | [Array\<keyof RsdoctorRspackPluginFeatures\>](#rsdoctorrspackpluginfeatures)
|
|
21
|
+
- **Optional:** `true`
|
|
22
|
+
- **Default:** `['loader', 'plugins', 'bundle']`
|
|
23
|
+
|
|
24
|
+
#### features values
|
|
25
|
+
|
|
26
|
+
:::tip
|
|
27
|
+
|
|
28
|
+
**If an "out of memory" error occurs, you can try the following:**
|
|
29
|
+
|
|
30
|
+
1. Open the **lite** mode。
|
|
31
|
+
2. Increase the node memory limit, for example: NODE_OPTIONS=--max-old-space-size=8096.
|
|
32
|
+
|
|
33
|
+
- Reason: During the build process, source code information is cached, which exceeds memory. Therefore, enabling the **"lite" mode** can help alleviate the problem.
|
|
34
|
+
- Difference: The difference between the "lite" mode and the normal mode is that source code information is no longer cached, only packaged code information is cached. Thus, the code analyzed on the page will also only be packaged.
|
|
35
|
+
|
|
36
|
+
:::
|
|
37
|
+
|
|
38
|
+
The `features` attribute is used to analyze the function switches, and the specific functional items are as follows:
|
|
39
|
+
|
|
40
|
+
- **loader**: Analysis of Loader time consumption and code compilation changes, enabled by default.
|
|
41
|
+
- **plugins**: Analysis of Plugins calls and time consumption, enabled by default.
|
|
42
|
+
- **bundle**: Analysis of build artifacts, enabled by default.
|
|
43
|
+
- **resolver**: resolver analysis, disabled by default.
|
|
44
|
+
- **lite**: lite mode. The difference between lite mode and normal mode is that source code information is no longer cached, only packaged code information is cached, so the code analyzed on the page will also be packaged. The default is normal mode.
|
|
45
|
+
|
|
46
|
+
Therefore, **the default configuration enables bundle analysis capabilities and Loader and Plugin build-time analysis**. The Resolver analysis capability is not enabled, and Rspack does not currently support Resolver analysis capabilities.
|
|
47
|
+
|
|
48
|
+
#### features types
|
|
49
|
+
|
|
50
|
+
- if the `features` is set as an `Array`, it will **open** the features which you define in this array **only**.
|
|
51
|
+
- if the `features` is set as an `Object`, it will **close** the features which you set the value is `false`.
|
|
52
|
+
|
|
53
|
+
#### RsdoctorWebpackPluginFeatures
|
|
54
|
+
|
|
55
|
+
The types of `features` are as follows:
|
|
56
|
+
|
|
57
|
+
import Features from '@zh/shared/features.md';
|
|
58
|
+
|
|
59
|
+
<Features />
|
|
60
|
+
|
|
61
|
+
#### RsdoctorRspackPluginFeatures
|
|
62
|
+
|
|
63
|
+
The types of `features` are as follows:
|
|
64
|
+
|
|
65
|
+
import FeaturesRspack from '@zh/shared/features-rspack.md';
|
|
66
|
+
|
|
67
|
+
<FeaturesRspack />
|
|
@@ -118,18 +118,54 @@ Therefore, **the default configuration enables bundle analysis capabilities and
|
|
|
118
118
|
- if the `features` is set as an `Array`, it will **open** the features which you define in this array **only**.
|
|
119
119
|
- if the `features` is set as an `Object`, it will **close** the features which you set the value is `false`.
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
### reportCodeType 参数
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
- Type: `{ noModuleSource?: boolean; noAssetsAndModuleSource?: boolean }`
|
|
124
|
+
- Optional: true
|
|
125
|
+
- Default: undefined
|
|
126
|
+
- Description
|
|
124
127
|
|
|
125
|
-
|
|
128
|
+
- 选择输出的分析数据:
|
|
126
129
|
|
|
127
|
-
|
|
130
|
+
- undefined 是所有完整数据;
|
|
131
|
+
- noModuleSource: true 是输出除了 module 代码之外的数据;Module 代码即 Bundle 内拆解出来的一个一个文件的打包模块代码。
|
|
132
|
+
- noAssetsAndModuleSource: true 是输出除了 module 代码和 Assets 产物代码之外的数据。
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
- Select the output analysis data:
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
- undefined is all complete data;
|
|
132
137
|
|
|
133
|
-
|
|
138
|
+
- noModuleSource: true is the output of data other than module code; Module code is the packaged module code of a file disassembled in the Bundle.
|
|
134
139
|
|
|
135
|
-
|
|
140
|
+
- noAssetsAndModuleSource: true is the output of data other than module code and Assets product code.
|
|
141
|
+
|
|
142
|
+
- Example
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
new WebDoctorWebpackPlugin({
|
|
146
|
+
disableClientServer: false, // 建议 CI 环境下关闭 server 能力,否则会卡住 pipeline 流程,检测 CI 环境可以使用 `process.env.CI_ACTOR`.
|
|
147
|
+
features: ['loader', 'bundle', 'plugins'],
|
|
148
|
+
reportCodeType: { noModuleSource: true } // { noAssetsAndModuleSource: true }
|
|
149
|
+
}),
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### disableTOSUpload
|
|
153
|
+
|
|
154
|
+
- Type: boolean
|
|
155
|
+
- Optional: true
|
|
156
|
+
- Default: false
|
|
157
|
+
- Description
|
|
158
|
+
|
|
159
|
+
开启或关闭需要 tos 上传, true 是关闭 tos 上传,false 是开启 tos 上传。
|
|
160
|
+
|
|
161
|
+
Turn tos upload on or off. True is to turn off tos upload, and false is tos upload on.
|
|
162
|
+
|
|
163
|
+
- Example
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
new WebDoctorWebpackPlugin({
|
|
167
|
+
disableClientServer: false, // 建议 CI 环境下关闭 server 能力,否则会卡住 pipeline 流程,检测 CI 环境可以使用 `process.env.CI_ACTOR`.
|
|
168
|
+
features: ['loader', 'bundle', 'plugins'],
|
|
169
|
+
disableTOSUpload: true,
|
|
170
|
+
}),
|
|
171
|
+
```
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
## Step 2: Register Plugin
|
|
2
|
+
|
|
3
|
+
After the dependency installation, you need to integrate the Rsdoctor plugin into your project. Below are some examples of common tools and frameworks:
|
|
4
|
+
|
|
5
|
+
### Rspack
|
|
6
|
+
|
|
7
|
+
Initialize the RsdoctorRspackPlugin in the [plugins](https://www.rspack.dev/config/plugins.html#plugins) of `rspack.config.js`:
|
|
8
|
+
|
|
9
|
+
```js title="rspack.config.js"
|
|
10
|
+
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
// ...
|
|
14
|
+
plugins: [
|
|
15
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
16
|
+
process.env.RSDOCTOR &&
|
|
17
|
+
new RsdoctorRspackPlugin({
|
|
18
|
+
// plugin options
|
|
19
|
+
}),
|
|
20
|
+
].filter(Boolean),
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
25
|
+
|
|
26
|
+
### Rsbuild
|
|
27
|
+
|
|
28
|
+
Initialize the RsdoctorRspackPlugin in the [tools.rspack](https://rsbuild.dev/config/tools/rspack) of `rsbuild.config.ts`:
|
|
29
|
+
|
|
30
|
+
```js title="rsbuild.config.ts"
|
|
31
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
// ...
|
|
35
|
+
tools: {
|
|
36
|
+
rspack(config, { appendPlugins }) {
|
|
37
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
38
|
+
if (process.env.RSDOCTOR) {
|
|
39
|
+
appendPlugins(
|
|
40
|
+
new RsdoctorRspackPlugin({
|
|
41
|
+
// plugin options
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
51
|
+
|
|
52
|
+
### Webpack
|
|
53
|
+
|
|
54
|
+
Initialize the RsdoctorWebpackPlugin in the [plugins](https://webpack.js.org/configuration/plugins/#plugins) of `webpack.config.js`:
|
|
55
|
+
|
|
56
|
+
```js title="webpack.config.js"
|
|
57
|
+
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
// ...
|
|
61
|
+
plugins: [
|
|
62
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
63
|
+
process.env.RSDOCTOR &&
|
|
64
|
+
new RsdoctorWebpackPlugin({
|
|
65
|
+
// plugin options
|
|
66
|
+
}),
|
|
67
|
+
].filter(Boolean),
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
72
|
+
|
|
73
|
+
### Modern.js Framework
|
|
74
|
+
|
|
75
|
+
Initialize the plugin in the [tools.rspack](https://modernjs.dev/configure/app/tools/rspack) of `modern.config.ts`:
|
|
76
|
+
|
|
77
|
+
```ts title="modern.config.ts"
|
|
78
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
// ...
|
|
82
|
+
tools: {
|
|
83
|
+
rspack(config, { appendPlugins }) {
|
|
84
|
+
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
85
|
+
if (process.env.RSDOCTOR) {
|
|
86
|
+
appendPlugins(
|
|
87
|
+
new RsdoctorRspackPlugin({
|
|
88
|
+
// plugin options
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
98
|
+
|
|
99
|
+
:::tip
|
|
100
|
+
For projects using Modern.js Webpack mode, please register the `RsdoctorWebpackPlugin` plugin through [tools.webpack](https://modernjs.dev/configure/app/tools/webpack).
|
|
101
|
+
:::
|
|
102
|
+
|
|
103
|
+
### Next.js Framework
|
|
104
|
+
|
|
105
|
+
Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.mjs`.
|
|
106
|
+
|
|
107
|
+
```ts title="next.config.mjs"
|
|
108
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
109
|
+
|
|
110
|
+
export default {
|
|
111
|
+
// ...
|
|
112
|
+
webpack: (config, { isServer }) => {
|
|
113
|
+
config.plugins.push(
|
|
114
|
+
new RsdoctorWebpackPlugin({
|
|
115
|
+
// plugin options
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return config;
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
125
|
+
|
|
126
|
+
#### 📢 Next.js Project Notice
|
|
127
|
+
|
|
128
|
+
1. Next.js Project Reporting Page Issues
|
|
129
|
+
|
|
130
|
+
For more details, see: [FAQ](../more/faq#nextjs)
|
|
131
|
+
|
|
132
|
+
2. Loader Analysis with Rules Overriding Not Supported in Next.js
|
|
133
|
+
|
|
134
|
+
For more details, see: [FAQ](../more/faq#nextjs)
|
|
135
|
+
|
|
136
|
+
### Vue Framework
|
|
137
|
+
|
|
138
|
+
Initialize the `@rsdoctor/webpack-plugin` or `@rsdoctor/rspack-plugin` plugin in the configuration file. Here is an example using `rsbuild`:
|
|
139
|
+
|
|
140
|
+
```ts title="rsbuild.config.ts"
|
|
141
|
+
import { defineConfig } from '@rsbuild/core';
|
|
142
|
+
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
143
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
144
|
+
|
|
145
|
+
export default defineConfig({
|
|
146
|
+
plugins: [pluginVue()],
|
|
147
|
+
performance: {
|
|
148
|
+
buildCache: false,
|
|
149
|
+
},
|
|
150
|
+
tools: {
|
|
151
|
+
bundlerChain: (chain, { CHAIN_ID }) => {
|
|
152
|
+
chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
|
|
153
|
+
{
|
|
154
|
+
// plugin options
|
|
155
|
+
},
|
|
156
|
+
]);
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
163
|
+
|
|
164
|
+
#### 📢 Vue Project Notice
|
|
165
|
+
|
|
166
|
+
Because `vue-loader` analysis is not supported at the moment, loader analysis is disabled by default for Vue projects. However, plugin and build artifact analysis can still be performed.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Step 3: Run Build
|
|
171
|
+
|
|
172
|
+
Now, you can run the **build** command in the project. After the build is complete, Rsdoctor will automatically open the analysis page of this build.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Enable Rsdoctor
|
|
176
|
+
RSDOCTOR=true npm run build
|
|
177
|
+
|
|
178
|
+
# Disable Rsdoctor
|
|
179
|
+
npm run build
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
:::tip
|
|
183
|
+
The Rsdoctor plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
184
|
+
:::
|
|
@@ -24,187 +24,6 @@ For projects based on Webpack, install the following dependencies:
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
import QuickStartShared from './quick-start-shared.mdx';
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Rspack
|
|
32
|
-
|
|
33
|
-
Initialize the RsdoctorRspackPlugin in the [plugins](https://www.rspack.dev/config/plugins.html#plugins) of `rspack.config.js`:
|
|
34
|
-
|
|
35
|
-
```js title="rspack.config.js"
|
|
36
|
-
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
37
|
-
|
|
38
|
-
module.exports = {
|
|
39
|
-
// ...
|
|
40
|
-
plugins: [
|
|
41
|
-
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
42
|
-
process.env.RSDOCTOR &&
|
|
43
|
-
new RsdoctorRspackPlugin({
|
|
44
|
-
// plugin options
|
|
45
|
-
}),
|
|
46
|
-
].filter(Boolean),
|
|
47
|
-
};
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
51
|
-
|
|
52
|
-
### Rsbuild
|
|
53
|
-
|
|
54
|
-
Initialize the RsdoctorRspackPlugin in the [tools.rspack](https://rsbuild.dev/config/tools/rspack) of `rsbuild.config.ts`:
|
|
55
|
-
|
|
56
|
-
```js title="rsbuild.config.ts"
|
|
57
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
// ...
|
|
61
|
-
tools: {
|
|
62
|
-
rspack(config, { appendPlugins }) {
|
|
63
|
-
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
64
|
-
if (process.env.RSDOCTOR) {
|
|
65
|
-
appendPlugins(
|
|
66
|
-
new RsdoctorRspackPlugin({
|
|
67
|
-
// plugin options
|
|
68
|
-
}),
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
77
|
-
|
|
78
|
-
### Webpack
|
|
79
|
-
|
|
80
|
-
Initialize the RsdoctorWebpackPlugin in the [plugins](https://webpack.js.org/configuration/plugins/#plugins) of `webpack.config.js`:
|
|
81
|
-
|
|
82
|
-
```js title="webpack.config.js"
|
|
83
|
-
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
// ...
|
|
87
|
-
plugins: [
|
|
88
|
-
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
89
|
-
process.env.RSDOCTOR &&
|
|
90
|
-
new RsdoctorWebpackPlugin({
|
|
91
|
-
// plugin options
|
|
92
|
-
}),
|
|
93
|
-
].filter(Boolean),
|
|
94
|
-
};
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
98
|
-
|
|
99
|
-
### Modern.js Framework
|
|
100
|
-
|
|
101
|
-
Initialize the plugin in the [tools.rspack](https://modernjs.dev/configure/app/tools/rspack) of `modern.config.ts`:
|
|
102
|
-
|
|
103
|
-
```ts title="modern.config.ts"
|
|
104
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
105
|
-
|
|
106
|
-
export default {
|
|
107
|
-
// ...
|
|
108
|
-
tools: {
|
|
109
|
-
rspack(config, { appendPlugins }) {
|
|
110
|
-
// Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
|
|
111
|
-
if (process.env.RSDOCTOR) {
|
|
112
|
-
appendPlugins(
|
|
113
|
-
new RsdoctorRspackPlugin({
|
|
114
|
-
// plugin options
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
124
|
-
|
|
125
|
-
:::tip
|
|
126
|
-
For projects using Modern.js Webpack mode, please register the `RsdoctorWebpackPlugin` plugin through [tools.webpack](https://modernjs.dev/configure/app/tools/webpack).
|
|
127
|
-
:::
|
|
128
|
-
|
|
129
|
-
### Next.js Framework
|
|
130
|
-
|
|
131
|
-
Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.mjs`.
|
|
132
|
-
|
|
133
|
-
```ts title="next.config.mjs"
|
|
134
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
135
|
-
|
|
136
|
-
export default {
|
|
137
|
-
// ...
|
|
138
|
-
webpack: (config, { isServer }) => {
|
|
139
|
-
config.plugins.push(
|
|
140
|
-
new RsdoctorWebpackPlugin({
|
|
141
|
-
// plugin options
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
return config;
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
151
|
-
|
|
152
|
-
#### 📢 Next.js Project Notice
|
|
153
|
-
|
|
154
|
-
1. Next.js Project Reporting Page Issues
|
|
155
|
-
|
|
156
|
-
For more details, see: [FAQ](../more/faq#nextjs)
|
|
157
|
-
|
|
158
|
-
2. Loader Analysis with Rules Overriding Not Supported in Next.js
|
|
159
|
-
|
|
160
|
-
For more details, see: [FAQ](../more/faq#nextjs)
|
|
161
|
-
|
|
162
|
-
### Vue Framework
|
|
163
|
-
|
|
164
|
-
Initialize the `@rsdoctor/webpack-plugin` or `@rsdoctor/rspack-plugin` plugin in the configuration file. Here is an example using `rsbuild`:
|
|
165
|
-
|
|
166
|
-
```ts title="rsbuild.config.ts"
|
|
167
|
-
import { defineConfig } from '@rsbuild/core';
|
|
168
|
-
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
169
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
170
|
-
|
|
171
|
-
export default defineConfig({
|
|
172
|
-
plugins: [pluginVue()],
|
|
173
|
-
performance: {
|
|
174
|
-
buildCache: false,
|
|
175
|
-
},
|
|
176
|
-
tools: {
|
|
177
|
-
bundlerChain: (chain, { CHAIN_ID }) => {
|
|
178
|
-
chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
|
|
179
|
-
{
|
|
180
|
-
// plugin options
|
|
181
|
-
},
|
|
182
|
-
]);
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
189
|
-
|
|
190
|
-
#### 📢 Vue Project Notice
|
|
191
|
-
|
|
192
|
-
Because `vue-loader` analysis is not supported at the moment, loader analysis is disabled by default for Vue projects. However, plugin and build artifact analysis can still be performed.
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
## Step 3: Run Build
|
|
197
|
-
|
|
198
|
-
Now, you can run the **build** command in the project. After the build is complete, Rsdoctor will automatically open the analysis page of this build.
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
# Enable Rsdoctor
|
|
202
|
-
RSDOCTOR=true npm run build
|
|
203
|
-
|
|
204
|
-
# Disable Rsdoctor
|
|
205
|
-
npm run build
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
:::tip
|
|
209
|
-
The Rsdoctor plugin provides some configurations, please refer to [Options](../../config/options/options).
|
|
210
|
-
:::
|
|
29
|
+
<QuickStartShared />
|
|
@@ -27,9 +27,9 @@ The meanings of the fields in the data statistics table on the page are as follo
|
|
|
27
27
|
|
|
28
28
|
## Usage Instructions
|
|
29
29
|
|
|
30
|
-
### View
|
|
30
|
+
### View Bundler Config
|
|
31
31
|
|
|
32
|
-
If we need to view the Webpack configuration of the project, we can click on `View
|
|
32
|
+
If we need to view the Rspack or Webpack configuration of the project, we can click on `View Bundler Config` in the upper right corner of the card. A floating layer will pop up, which contains the serialized **Bundler Config**, as shown in the following figure:
|
|
33
33
|
|
|
34
34
|
<img
|
|
35
35
|
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/compile/plugins-analysis-config.png"
|
|
@@ -28,9 +28,9 @@ In the main page of **Rsdoctor**, we can see a card named `Project Overall`, whi
|
|
|
28
28
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
|
-
### View
|
|
31
|
+
### View Bundler Config
|
|
32
32
|
|
|
33
|
-
If we need to view the Webpack configuration of the project, we can click on `View
|
|
33
|
+
If we need to view the Rspack or Webpack configuration of the project, we can click on `View Bundler Config` in the top right corner of the card. A popup window will appear, containing the serialized [Bundler Config](https://webpack.js.org/configuration/), as shown in the following image:
|
|
34
34
|
|
|
35
35
|
<img
|
|
36
36
|
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/project-overall-config.jpg"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
## Options
|
|
2
|
+
|
|
3
|
+
**类型:** `Object`
|
|
4
|
+
|
|
5
|
+
这个 `Options` 是 [RsdoctorWebpackPlugin](#rsdoctorwebpackplugin-%E6%8F%92%E4%BB%B6) 和 [RsdoctorRspackPlugin](#rsdoctorrspackplugin-%E6%8F%92%E4%BB%B6) 的配置项。它包含以下属性值:
|
|
6
|
+
|
|
7
|
+
- [disableClientServer](#disableclientserver)
|
|
8
|
+
- [features](#features)
|
|
9
|
+
|
|
10
|
+
### disableClientServer
|
|
11
|
+
|
|
12
|
+
- **Type:** `boolean`
|
|
13
|
+
- **Optional:** `true`
|
|
14
|
+
- **Default:** `false`
|
|
15
|
+
|
|
16
|
+
:::tip
|
|
17
|
+
建议在 CI 环境下将 disableClientServer 设置为 true,否则启动的服务会卡住 pipeline 流程.
|
|
18
|
+
:::
|
|
19
|
+
|
|
20
|
+
是否需要自动打开 Rsdoctor 报告页面。如果你不需要在浏览器内查看本次 Rsdoctor 提供的分析报告,则可以开启这个配置项。
|
|
21
|
+
|
|
22
|
+
### features
|
|
23
|
+
|
|
24
|
+
- **Type:** [RsdoctorWebpackPluginFeatures](#rsdoctorwebpackpluginfeatures) | [Array\<keyof RsdoctorWebpackPluginFeatures\>](#rsdoctorwebpackpluginfeatures) | [RsdoctorRspackPluginFeatures](#rsdoctorrspackpluginfeatures) | [Array\<keyof RsdoctorRspackPluginFeatures\>](#rsdoctorrspackpluginfeatures)
|
|
25
|
+
- **Optional:** `true`
|
|
26
|
+
- **Default:** `['loader', 'plugins', 'bundle']`
|
|
27
|
+
|
|
28
|
+
#### features values
|
|
29
|
+
|
|
30
|
+
:::tip
|
|
31
|
+
**如果出现了 out of memory 的报错,可以尝试:**
|
|
32
|
+
|
|
33
|
+
1. 打开 **lite** 模式。
|
|
34
|
+
2. 增大 node 内存上限,例如:NODE_OPTIONS=--max-old-space-size=8096。
|
|
35
|
+
|
|
36
|
+
- 原因:因为构建过程中,缓存了源码信息,超过了内存,所以开启 `lite` 模式可以缓解。
|
|
37
|
+
- 区别:`lite` 模式和普通模式的区别就是不再缓存源码信息,只缓存打包后的代码信息,这样分析页面上的代码也将是打包后的。
|
|
38
|
+
|
|
39
|
+
:::
|
|
40
|
+
|
|
41
|
+
features 属性是用于分析功能开关的,具体的功能项如下:
|
|
42
|
+
|
|
43
|
+
- **loader**:Loaders 耗时及代码编译变化分析,默认开启。
|
|
44
|
+
- **plugins**:Plugins 调用以及耗时分析,默认开启。
|
|
45
|
+
- **bundle**:构建产物分析,默认开启。
|
|
46
|
+
- **resolver**:resolver 分析,默认关闭。
|
|
47
|
+
- **lite**: lite 模式。lite 模式和普通模式的区别就是不再缓存源码信息,只缓存打包后的代码信息,这样分析页面上的代码也将是打包后的。默认普通模式。
|
|
48
|
+
|
|
49
|
+
所以,**默认配置是开启了 Bundle 分析能力、 Loader he Plugin 构建时分析**。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。
|
|
50
|
+
|
|
51
|
+
#### features types
|
|
52
|
+
|
|
53
|
+
- 如果你将 `features` 设置为**数组**类型,该插件**只会开启**你在 `features` 数组中定义的功能。
|
|
54
|
+
- 如果你将 `features` 设置为**简单对象**类型,该插件**只会关闭**你在 `features` 对象中值为 `false` 的功能。
|
|
55
|
+
|
|
56
|
+
#### RsdoctorWebpackPluginFeatures
|
|
57
|
+
|
|
58
|
+
`features` 类型如下:
|
|
59
|
+
|
|
60
|
+
import Features from '@zh/shared/features.md';
|
|
61
|
+
|
|
62
|
+
<Features />
|
|
63
|
+
|
|
64
|
+
#### RsdoctorRspackPluginFeatures
|
|
65
|
+
|
|
66
|
+
`features` 类型如下:
|
|
67
|
+
|
|
68
|
+
import FeaturesRspack from '@zh/shared/features-rspack.md';
|
|
69
|
+
|
|
70
|
+
<FeaturesRspack />
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
## 第二步:注册插件
|
|
2
|
+
|
|
3
|
+
依赖安装完成后,你需要在项目中接入 Rsdoctor 插件,下面是一些常见工具和框架的示例:
|
|
4
|
+
|
|
5
|
+
### Rspack 项目
|
|
6
|
+
|
|
7
|
+
在 `rspack.config.js` 的 [plugins](https://www.rspack.dev/config/plugins.html#plugins) 中初始化 RsdoctorRspackPlugin 插件,参考:
|
|
8
|
+
|
|
9
|
+
```js title="rspack.config.js"
|
|
10
|
+
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
// ...
|
|
14
|
+
plugins: [
|
|
15
|
+
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
16
|
+
process.env.RSDOCTOR &&
|
|
17
|
+
new RsdoctorRspackPlugin({
|
|
18
|
+
// 插件选项
|
|
19
|
+
}),
|
|
20
|
+
].filter(Boolean),
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
25
|
+
|
|
26
|
+
### Rsbuild 项目
|
|
27
|
+
|
|
28
|
+
在 `rsbuild.config.ts` 的 [tools.rspack](https://rsbuild.dev/config/tools/rspack) 中初始化 RsdoctorWebpackPlugin 插件,参考:
|
|
29
|
+
|
|
30
|
+
```js title="rsbuild.config.ts"
|
|
31
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
// ...
|
|
35
|
+
tools: {
|
|
36
|
+
rspack(config, { appendPlugins }) {
|
|
37
|
+
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
38
|
+
if (process.env.RSDOCTOR) {
|
|
39
|
+
appendPlugins(
|
|
40
|
+
new RsdoctorRspackPlugin({
|
|
41
|
+
// 插件选项
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
51
|
+
|
|
52
|
+
### Webpack 项目
|
|
53
|
+
|
|
54
|
+
在 `webpack.config.js` 的 [plugins](https://webpack.js.org/configuration/plugins/#plugins) 中初始化 RsdoctorWebpackPlugin 插件,参考:
|
|
55
|
+
|
|
56
|
+
```js title="webpack.config.js"
|
|
57
|
+
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
// ...
|
|
61
|
+
plugins: [
|
|
62
|
+
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
63
|
+
process.env.RSDOCTOR &&
|
|
64
|
+
new RsdoctorWebpackPlugin({
|
|
65
|
+
// 插件选项
|
|
66
|
+
}),
|
|
67
|
+
].filter(Boolean),
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
72
|
+
|
|
73
|
+
### Modern.js 项目
|
|
74
|
+
|
|
75
|
+
在 `modern.config.ts` 的 [tools.bundlerChain](https://modernjs.dev/configure/app/tools/rspack) 中初始化插件,参考:
|
|
76
|
+
|
|
77
|
+
```ts title="modern.config.ts"
|
|
78
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
// ...
|
|
82
|
+
tools: {
|
|
83
|
+
rspack(config, { appendPlugins }) {
|
|
84
|
+
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
85
|
+
if (process.env.RSDOCTOR) {
|
|
86
|
+
appendPlugins(
|
|
87
|
+
new RsdoctorRspackPlugin({
|
|
88
|
+
// 插件选项
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
98
|
+
|
|
99
|
+
:::tip
|
|
100
|
+
对于使用 Modern.js Webpack 模式的项目,请使用 [tools.webpack](https://modernjs.dev/configure/app/tools/webpack) 注册 `RsdoctorWebpackPlugin` 插件。
|
|
101
|
+
:::
|
|
102
|
+
|
|
103
|
+
### Next.js 项目
|
|
104
|
+
|
|
105
|
+
在 `next.config.js` 的 [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) 中初始化 RsdoctorWebpackPlugin 插件。
|
|
106
|
+
|
|
107
|
+
```ts title="next.config.mjs"
|
|
108
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
109
|
+
|
|
110
|
+
export default {
|
|
111
|
+
// ...
|
|
112
|
+
webpack: (config, { isServer }) => {
|
|
113
|
+
config.plugins.push(
|
|
114
|
+
new RsdoctorWebpackPlugin({
|
|
115
|
+
// 插件选项
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
return config;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
124
|
+
|
|
125
|
+
#### 📢 Next.js 项目使用注意
|
|
126
|
+
|
|
127
|
+
1. Next.js 项目报告页面问题
|
|
128
|
+
|
|
129
|
+
详情查看:[FAQ](../more/faq#nextjs)
|
|
130
|
+
|
|
131
|
+
2. Next.js 中不支持对 rules 进行重写的 Loader 分析
|
|
132
|
+
|
|
133
|
+
详情查看:[FAQ](../more/faq#nextjs)
|
|
134
|
+
|
|
135
|
+
### Vue 项目
|
|
136
|
+
|
|
137
|
+
在配置文件中初始化 `@rsdoctor/webpack-plugin` 或 `@rsdoctor/rspack-plugin` 插件,以下是使用 rsbuild 项目作为示例:
|
|
138
|
+
|
|
139
|
+
```ts title="rsbuild.config.ts"
|
|
140
|
+
import { defineConfig } from '@rsbuild/core';
|
|
141
|
+
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
142
|
+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
143
|
+
|
|
144
|
+
export default defineConfig({
|
|
145
|
+
plugins: [pluginVue()],
|
|
146
|
+
performance: {
|
|
147
|
+
buildCache: false,
|
|
148
|
+
},
|
|
149
|
+
tools: {
|
|
150
|
+
bundlerChain: (chain, { CHAIN_ID }) => {
|
|
151
|
+
chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
|
|
152
|
+
{
|
|
153
|
+
// 插件选项
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
162
|
+
|
|
163
|
+
#### 📢 Vue 项目使用注意
|
|
164
|
+
|
|
165
|
+
由于目前不支持对 `vue-loader` 进行分析,对于 Vue 项目,默认情况下禁用了 loader 分析。但是,仍然可以进行插件和构建产物的分析。
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## 第三步:执行构建
|
|
170
|
+
|
|
171
|
+
现在你可以在项目内执行 **build** 命令,在完成构建后,Rsdoctor 会自动打开本次构建的分析页面。
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# 开启 Rsdoctor
|
|
175
|
+
RSDOCTOR=true npm run build
|
|
176
|
+
|
|
177
|
+
# 未开启 Rsdoctor
|
|
178
|
+
npm run build
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
:::tip
|
|
182
|
+
Rsdoctor 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
183
|
+
:::
|
|
@@ -24,186 +24,6 @@ import { PackageManagerTabs } from '@theme';
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
import QuickStartShared from './quick-start-shared.mdx';
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Rspack 项目
|
|
32
|
-
|
|
33
|
-
在 `rspack.config.js` 的 [plugins](https://www.rspack.dev/config/plugins.html#plugins) 中初始化 RsdoctorRspackPlugin 插件,参考:
|
|
34
|
-
|
|
35
|
-
```js title="rspack.config.js"
|
|
36
|
-
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
37
|
-
|
|
38
|
-
module.exports = {
|
|
39
|
-
// ...
|
|
40
|
-
plugins: [
|
|
41
|
-
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
42
|
-
process.env.RSDOCTOR &&
|
|
43
|
-
new RsdoctorRspackPlugin({
|
|
44
|
-
// 插件选项
|
|
45
|
-
}),
|
|
46
|
-
].filter(Boolean),
|
|
47
|
-
};
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
51
|
-
|
|
52
|
-
### Rsbuild 项目
|
|
53
|
-
|
|
54
|
-
在 `rsbuild.config.ts` 的 [tools.rspack](https://rsbuild.dev/config/tools/rspack) 中初始化 RsdoctorWebpackPlugin 插件,参考:
|
|
55
|
-
|
|
56
|
-
```js title="rsbuild.config.ts"
|
|
57
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
58
|
-
|
|
59
|
-
export default {
|
|
60
|
-
// ...
|
|
61
|
-
tools: {
|
|
62
|
-
rspack(config, { appendPlugins }) {
|
|
63
|
-
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
64
|
-
if (process.env.RSDOCTOR) {
|
|
65
|
-
appendPlugins(
|
|
66
|
-
new RsdoctorRspackPlugin({
|
|
67
|
-
// 插件选项
|
|
68
|
-
}),
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
77
|
-
|
|
78
|
-
### Webpack 项目
|
|
79
|
-
|
|
80
|
-
在 `webpack.config.js` 的 [plugins](https://webpack.js.org/configuration/plugins/#plugins) 中初始化 RsdoctorWebpackPlugin 插件,参考:
|
|
81
|
-
|
|
82
|
-
```js title="webpack.config.js"
|
|
83
|
-
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
// ...
|
|
87
|
-
plugins: [
|
|
88
|
-
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
89
|
-
process.env.RSDOCTOR &&
|
|
90
|
-
new RsdoctorWebpackPlugin({
|
|
91
|
-
// 插件选项
|
|
92
|
-
}),
|
|
93
|
-
].filter(Boolean),
|
|
94
|
-
};
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
98
|
-
|
|
99
|
-
### Modern.js 项目
|
|
100
|
-
|
|
101
|
-
在 `modern.config.ts` 的 [tools.bundlerChain](https://modernjs.dev/configure/app/tools/rspack) 中初始化插件,参考:
|
|
102
|
-
|
|
103
|
-
```ts title="modern.config.ts"
|
|
104
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
105
|
-
|
|
106
|
-
export default {
|
|
107
|
-
// ...
|
|
108
|
-
tools: {
|
|
109
|
-
rspack(config, { appendPlugins }) {
|
|
110
|
-
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
111
|
-
if (process.env.RSDOCTOR) {
|
|
112
|
-
appendPlugins(
|
|
113
|
-
new RsdoctorRspackPlugin({
|
|
114
|
-
// 插件选项
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
124
|
-
|
|
125
|
-
:::tip
|
|
126
|
-
对于使用 Modern.js Webpack 模式的项目,请使用 [tools.webpack](https://modernjs.dev/configure/app/tools/webpack) 注册 `RsdoctorWebpackPlugin` 插件。
|
|
127
|
-
:::
|
|
128
|
-
|
|
129
|
-
### Next.js 项目
|
|
130
|
-
|
|
131
|
-
在 `next.config.js` 的 [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) 中初始化 RsdoctorWebpackPlugin 插件。
|
|
132
|
-
|
|
133
|
-
```ts title="next.config.mjs"
|
|
134
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
135
|
-
|
|
136
|
-
export default {
|
|
137
|
-
// ...
|
|
138
|
-
webpack: (config, { isServer }) => {
|
|
139
|
-
config.plugins.push(
|
|
140
|
-
new RsdoctorWebpackPlugin({
|
|
141
|
-
// 插件选项
|
|
142
|
-
}),
|
|
143
|
-
);
|
|
144
|
-
return config;
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
150
|
-
|
|
151
|
-
#### 📢 Next.js 项目使用注意
|
|
152
|
-
|
|
153
|
-
1. Next.js 项目报告页面问题
|
|
154
|
-
|
|
155
|
-
详情查看:[FAQ](../more/faq#nextjs)
|
|
156
|
-
|
|
157
|
-
2. Next.js 中不支持对 rules 进行重写的 Loader 分析
|
|
158
|
-
|
|
159
|
-
详情查看:[FAQ](../more/faq#nextjs)
|
|
160
|
-
|
|
161
|
-
### Vue 项目
|
|
162
|
-
|
|
163
|
-
在配置文件中初始化 `@rsdoctor/webpack-plugin` 或 `@rsdoctor/rspack-plugin` 插件,以下是使用 rsbuild 项目作为示例:
|
|
164
|
-
|
|
165
|
-
```ts title="rsbuild.config.ts"
|
|
166
|
-
import { defineConfig } from '@rsbuild/core';
|
|
167
|
-
import { pluginVue } from '@rsbuild/plugin-vue';
|
|
168
|
-
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
169
|
-
|
|
170
|
-
export default defineConfig({
|
|
171
|
-
plugins: [pluginVue()],
|
|
172
|
-
performance: {
|
|
173
|
-
buildCache: false,
|
|
174
|
-
},
|
|
175
|
-
tools: {
|
|
176
|
-
bundlerChain: (chain, { CHAIN_ID }) => {
|
|
177
|
-
chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
|
|
178
|
-
{
|
|
179
|
-
// 插件选项
|
|
180
|
-
},
|
|
181
|
-
]);
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
188
|
-
|
|
189
|
-
#### 📢 Vue 项目使用注意
|
|
190
|
-
|
|
191
|
-
由于目前不支持对 `vue-loader` 进行分析,对于 Vue 项目,默认情况下禁用了 loader 分析。但是,仍然可以进行插件和构建产物的分析。
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
## 第三步:执行构建
|
|
196
|
-
|
|
197
|
-
现在你可以在项目内执行 **build** 命令,在完成构建后,Rsdoctor 会自动打开本次构建的分析页面。
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
# 开启 Rsdoctor
|
|
201
|
-
RSDOCTOR=true npm run build
|
|
202
|
-
|
|
203
|
-
# 未开启 Rsdoctor
|
|
204
|
-
npm run build
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
:::tip
|
|
208
|
-
Rsdoctor 插件提供了一些配置项,请参考 [Options](../../config/options/options)。
|
|
209
|
-
:::
|
|
29
|
+
<QuickStartShared />
|
|
@@ -27,9 +27,9 @@ plugin 耗时中会计算 Rsdoctor 的内部插件耗时。
|
|
|
27
27
|
|
|
28
28
|
## 使用说明
|
|
29
29
|
|
|
30
|
-
### View
|
|
30
|
+
### View Bundler Config
|
|
31
31
|
|
|
32
|
-
如果我们需要查看项目的 Webpack 配置,则可以通过点击卡片右上角的 `View
|
|
32
|
+
如果我们需要查看项目的 Rspack 或 Webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 **Bundler Config**,如下图所示:
|
|
33
33
|
|
|
34
34
|
<img
|
|
35
35
|
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/compile/plugins-analysis-config.png"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
|
|
29
29
|
## 使用说明
|
|
30
30
|
|
|
31
|
-
### View
|
|
31
|
+
### View Bundler Config
|
|
32
32
|
|
|
33
|
-
如果我们需要查看项目的 Webpack 配置,则可以通过点击卡片右上角的 `View
|
|
33
|
+
如果我们需要查看项目的 Rspack 或 Webpack 配置,则可以通过点击卡片右上角的 `View Bundler Config`,页面会弹出一个浮层,其中包含被序列化后的 [Bundler Config](https://webpack.js.org/configuration/),如下图所示:
|
|
34
34
|
|
|
35
35
|
<img
|
|
36
36
|
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/lognuvj/rsdoctor/docs/usage/project-overall-config.jpg"
|
package/package.json
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/docs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"scripts": {
|
|
5
|
-
"dev": "rspress dev",
|
|
6
|
-
"build": "rspress build",
|
|
7
|
-
"preview": "rspress preview"
|
|
8
|
-
},
|
|
3
|
+
"version": "0.1.9-beta.1",
|
|
9
4
|
"repository": {
|
|
10
5
|
"type": "git",
|
|
11
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -20,25 +15,30 @@
|
|
|
20
15
|
],
|
|
21
16
|
"publishConfig": {
|
|
22
17
|
"access": "public",
|
|
23
|
-
"provenance":
|
|
18
|
+
"provenance": true,
|
|
24
19
|
"registry": "https://registry.npmjs.org/"
|
|
25
20
|
},
|
|
26
21
|
"devDependencies": {
|
|
27
|
-
"@rsdoctor/types": "workspace:*",
|
|
28
22
|
"@types/node": "^16",
|
|
29
23
|
"@types/react": "^18",
|
|
30
24
|
"@types/react-dom": "^18",
|
|
31
25
|
"react": "18.2.0",
|
|
32
26
|
"react-dom": "18.2.0",
|
|
27
|
+
"rsbuild-plugin-google-analytics": "^1.0.0",
|
|
33
28
|
"rspress-plugin-font-open-sans": "^1.0.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
29
|
+
"typescript": "^5.2.2",
|
|
30
|
+
"@rsdoctor/types": "0.1.9-beta.1"
|
|
36
31
|
},
|
|
37
32
|
"dependencies": {
|
|
38
33
|
"framer-motion": "^10.17.6",
|
|
39
34
|
"react-markdown": "^9.0.1",
|
|
40
35
|
"rsfamily-nav-icon": "^1.0.2",
|
|
41
|
-
"rspress": "^1.
|
|
36
|
+
"rspress": "^1.16.1",
|
|
42
37
|
"tailwindcss": "^3.4.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"dev": "rspress dev",
|
|
41
|
+
"build": "rspress build",
|
|
42
|
+
"preview": "rspress preview"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|