Skip to content

Commit 2a6111b

Browse files
authored
docs: update the nextjs in rspack to use rsdoctor (#994)
1 parent f69963b commit 2a6111b

File tree

2 files changed

+124
-23
lines changed

2 files changed

+124
-23
lines changed

packages/document/docs/en/guide/start/quick-start-shared.mdx

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848

4949
- **Options:** The plugin provides some configurations, please refer to [Options](../../config/options/options).
5050

51-
### Modern.js Framework
51+
### Modern.js
5252

5353
Initialize the plugin in the [tools.rspack](https://modernjs.dev/configure/app/tools/rspack) of `modern.config.ts`:
5454

@@ -78,9 +78,51 @@ export default {
7878
For projects using Modern.js's webpack mode, please register the `RsdoctorWebpackPlugin` plugin through [tools.webpack](https://modernjs.dev/configure/app/tools/webpack).
7979
:::
8080

81-
### Next.js Framework
81+
### Next.js
8282

83-
Initialize the RsdoctorWebpackPlugin plugin in the [Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) of `next.config.ts`.
83+
#### Step 1: Register the Rsdoctor plugin
84+
85+
Initialize the [RsdoctorRspackPlugin](#rspack-projects)([RsdoctorWebpackPlugin](#webpack-projects)) plugin in the [Rspack Config](https://rspack.dev/guide/tech/next)([webpack config](https://nextjs.org/docs/pages/api-reference/config/next-config-js/webpack)) of `next.config.ts`.
86+
87+
import { Tab, Tabs } from 'rspress/theme';
88+
89+
<Tabs>
90+
91+
<Tab label="Rspack">
92+
93+
```ts title="next.config.ts"
94+
import type { NextConfig } from 'next';
95+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
96+
97+
const nextConfig: NextConfig = {
98+
/* config options here */
99+
webpack: (config) => {
100+
if (config.name === 'client') {
101+
config.plugins.push(
102+
new RsdoctorRspackPlugin({
103+
disableClientServer: true,
104+
}),
105+
);
106+
} else if (config.name === 'server') {
107+
config.plugins.push(
108+
new RsdoctorRspackPlugin({
109+
disableClientServer: true,
110+
output: {
111+
reportDir: './.next/server',
112+
},
113+
}),
114+
);
115+
}
116+
return config;
117+
},
118+
};
119+
120+
export default nextConfig;
121+
```
122+
123+
</Tab>
124+
125+
<Tab label="webpack">
84126

85127
```ts title="next.config.ts"
86128
import type { NextConfig } from 'next';
@@ -112,28 +154,37 @@ const nextConfig: NextConfig = {
112154
export default nextConfig;
113155
```
114156

115-
- **Options:** The plugin provides some configuration options, please refer to [Options](../../config/options/options).
157+
</Tab>
158+
</Tabs>
116159

117-
#### 📢 Note for Next.js projects
160+
- **Options:** The plugin provides some configuration options, please refer to [Options](../../config/options/options).
118161

119-
Since Next.js closes the terminal service after the `build` execution is completed, the report page server run by Rsdoctor during the build process will also be shut down. At this point, you can reopen the report page using [@rsdoctor/cli](/guide/start/cli) without having to execute the build operation again.
162+
#### Step 2: Execute build
120163

121-
- First, install [@rsdoctor/cli](/guide/start/cli):
164+
Execute the **build** command, Rsdoctor will generate the corresponding report data in the local repository artifacts.
122165

123166
import { PackageManagerTabs } from '@theme';
124167

125-
<PackageManagerTabs command="add @rsdoctor/cli -D" />
168+
<PackageManagerTabs command="run build" />
126169

127-
- Second, add the following scripts commands to **package.json**, executing **client:rsdoctor** or **server:rsdoctor** can open the report for the corresponding builder:
170+
#### Step 3: Open the report
171+
172+
After installing [@rsdoctor/cli](/guide/start/cli), add the following scripts commands to **package.json**, executing **client:rsd** or **server:rsd** can open the report of the corresponding builder:
173+
174+
<PackageManagerTabs command="add @rsdoctor/cli -D" />
128175

129176
```ts
130177
"scripts": {
131-
"client:rsdoctor": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json",
132-
"server:rsdoctor": "rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json"
178+
"client:rsd": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json", // Rsdoctor's client report
179+
"server:rsd": "rsdoctor analyze --profile .next/server/.rsdoctor/manifest.json" // Rsdoctor's server report
133180
}
134181
```
135182

136-
For example, if Rsdoctor's build artifacts are located at the `.next/server/chunks/.rsdoctor/manifest.json` path, you can open the report page by executing the following command:
183+
#### 📢 Note for Next.js
184+
185+
After Next.js finishes executing the `build` command, it will terminate the terminal service, causing the report page server run by Rsdoctor during the build process to close. To solve this problem, you can use [@rsdoctor/cli](/guide/start/cli) to reopen the report page without re-executing the build operation. The specific method is shown in the [third step](#step-3-open-the-report) or by locally executing the rsdoctor command:
186+
187+
For example, if Rsdoctor's build output is located at the path `.next/server/chunks/.rsdoctor/manifest.json`, you can open the report page by executing the following command:
137188

138189
```bash
139190
rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json
@@ -170,7 +221,7 @@ export default defineConfig({
170221

171222
---
172223

173-
## Step 3: run build
224+
## Step 3: Execute build
174225

175226
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.
176227

packages/document/docs/zh/guide/start/quick-start-shared.mdx

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,48 @@ export default {
8080

8181
### Next.js 项目
8282

83-
`next.config.js`[Webpack Config](https://nextjs.org/docs/app/api-reference/next-config-js/webpack) 中初始化 RsdoctorWebpackPlugin 插件。
83+
#### 第一步:注册 Rsdoctor 插件
84+
85+
`next.config.ts`[Rspack 配置](https://rspack.dev/guide/tech/next)([webpack 配置](https://nextjs.org/docs/pages/api-reference/config/next-config-js/webpack)) 中初始化 [RsdoctorRspackPlugin](#rspack-%E9%A1%B9%E7%9B%AE)[RsdoctorWebpackPlugin](#webpack-%E9%A1%B9%E7%9B%AE)) 插件。
86+
87+
import { Tab, Tabs } from 'rspress/theme';
88+
89+
<Tabs>
90+
<Tab label="Rspack">
91+
92+
```ts title="next.config.ts"
93+
import type { NextConfig } from 'next';
94+
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
95+
96+
const nextConfig: NextConfig = {
97+
/* config options here */
98+
webpack: (config) => {
99+
if (config.name === 'client') {
100+
config.plugins.push(
101+
new RsdoctorRspackPlugin({
102+
disableClientServer: true,
103+
}),
104+
);
105+
} else if (config.name === 'server') {
106+
config.plugins.push(
107+
new RsdoctorRspackPlugin({
108+
disableClientServer: true,
109+
output: {
110+
reportDir: './.next/server',
111+
},
112+
}),
113+
);
114+
}
115+
return config;
116+
},
117+
};
118+
119+
export default nextConfig;
120+
```
121+
122+
</Tab>
123+
124+
<Tab label="webpack">
84125

85126
```ts title="next.config.ts"
86127
import type { NextConfig } from 'next';
@@ -112,28 +153,37 @@ const nextConfig: NextConfig = {
112153
export default nextConfig;
113154
```
114155

115-
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)
156+
</Tab>
157+
</Tabs>
116158

117-
#### 📢 Next.js 项目使用注意
159+
- **Options:** 插件提供了一些配置项,请参考 [Options](../../config/options/options)
118160

119-
由于 Next.js 在 `build` 执行结束后会终止终端服务,因此 Rsdoctor 在构建过程中运行的报告页面服务器也会被关闭。此时,你可以通过 [@rsdoctor/cli](/guide/start/cli) 再次打开页面报告,而无需重新执行构建操作。
161+
#### 第二步:执行构建
120162

121-
- 首先,安装 [@rsdoctor/cli](/guide/start/cli)
163+
执行 **build** 命令,Rsdoctor 会在本地仓库产物中生成对应的报告数据。
122164

123165
import { PackageManagerTabs } from '@theme';
124166

125-
<PackageManagerTabs command="add @rsdoctor/cli -D" />
167+
<PackageManagerTabs command="run build" />
168+
169+
#### 第三步:打开报告
126170

127-
- 其次,**package.json** 里添加如下 scripts 命令,执行 **client:rsdoctor** 或者 **server:rsdoctor** 可打开对应构建器的报告:
171+
安装 [@rsdoctor/cli](/guide/start/cli) 后,**package.json** 里添加如下 scripts 命令,执行 **client:rsd** 或者 **server:rsd** 可打开对应构建器的报告:
172+
173+
<PackageManagerTabs command="add @rsdoctor/cli -D" />
128174

129175
```ts
130176
"scripts": {
131-
"client:rsdoctor": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json",
132-
"server:rsdoctor": "rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json"
177+
"client:rsd": "rsdoctor analyze --profile .next/.rsdoctor/manifest.json", // Rsdoctor's client report path
178+
"server:rsd": "rsdoctor analyze --profile .next/server/.rsdoctor/manifest.json" // Rsdoctor's server report path
133179
}
134180
```
135181

136-
例如:Rsdoctor 的构建产物在 `.next/server/chunks/.rsdoctor/manifest.json` 路径,则可通过执行下面命令来打开报告页面:
182+
#### 📢 Next.js 项目使用注意
183+
184+
Next.js 在 `build` 执行结束后会终止终端服务,导致 Rsdoctor 在构建过程中运行的报告页面服务器关闭。为解决此问题,你可以使用 [@rsdoctor/cli](/guide/start/cli) 重新打开报告页面,无需重新执行构建操作。具体方法见[第三步](#%E7%AC%AC%E4%B8%89%E6%AD%A5%E6%89%93%E5%BC%80%E6%8A%A5%E5%91%8A)或本地执行 rsdoctor 命令:
185+
186+
例如 Rsdoctor 的构建产物在 `.next/server/chunks/.rsdoctor/manifest.json` 路径,则可通过执行下面命令来打开报告页面:
137187

138188
```bash
139189
rsdoctor analyze --profile .next/server/chunks/.rsdoctor/manifest.json

0 commit comments

Comments
 (0)