Options 配置
RsdoctorRspackPlugin 插件
RsdoctorRspackPlugin 类由 @rsdoctor/rspack-plugin
导出,配置项是 RsdoctorRspackPluginOptions。
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
new RsdoctorRspackPlugin({
/** RsdoctorRspackPluginOptions */
});
RsdoctorWebpackPlugin 插件
RsdoctorWebpackPlugin 类由 @rsdoctor/webpack-plugin
导出,配置项是 RsdoctorWebpackPluginOptions。
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
new RsdoctorWebpackPlugin({
/** RsdoctorWebpackPluginOptions */
});
Options
类型: Object
这个 Options
是 RsdoctorWebpackPlugin 和 RsdoctorRspackPlugin 的配置项。它包含以下属性值:
brief
Version: 0.4.0
Brief 模式更多配置,如下:
- reportHtmlName: 配置 Brief 的 HTML 报告的名称,默认
report-rsdoctor.html
。
- writeDataJson: 默认 Brief 模式下将分析数据注入到 HTML 文件中,所以不会再产生构建分析数据。如果想要而外本地生成数据则需要配置
writeDataJson: true
。
briefType
interface BriefConfig {
reportHtmlName?: string | undefined;
writeDataJson: boolean;
}
disableClientServer
- 类型:
boolean
- 可选:
true
- 默认值:
false
TIP
建议在 CI 环境下将 disableClientServer 设置为 true,否则启动的服务会卡住 pipeline 流程.
是否需要自动打开 Rsdoctor 报告页面。如果你不需要在浏览器内查看本次 Rsdoctor 提供的分析报告,则可以开启这个配置项。
experiments
Version: 1.0.0
enableNativePlugin
- 类型:
boolean
- 可选:
true
- 默认值:
false
Description
通过在 Rspack 中集成 Rsdoctor 的原生插件,我们将 Rsdoctor 中耗时较大的数据处理逻辑前置到 Rspack 的构建阶段。这一特性显著提升了 Rspack 中 Rsdoctor 的构建分析效率,减少了整体分析时间。
new RsdoctorRspackPlugin({
experiments: { enableNativePlugin: true }
}),
features
features values
features 属性是用于分析功能开关的,具体的功能项如下:
- loader:Loaders 耗时及代码编译变化分析,默认开启。
- plugins:Plugins 调用以及耗时分析,默认开启。
- bundle:构建产物分析,默认开启。
- resolver:resolver 分析,默认关闭。
- lite: (废弃,使用 mode.lite) lite 模式。lite 模式和普通模式的区别就是不再展示源码信息,只展示打包后的代码信息,这样分析页面上的代码也将是打包后的。默认普通模式。
所以,默认配置是开启了 Bundle 分析能力、 Loader 和 Plugin 构建时分析。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。
TIP
如果出现了 out of memory 的报错,可以尝试:
- 打开 lite 模式。
- 增大 node 内存上限,例如:NODE_OPTIONS=--max-old-space-size=8096。
- 原因:因为构建过程中,缓存了源码信息,超过了内存,所以开启
lite
模式可以缓解。
- 区别:
lite
模式和普通模式的区别就是不再缓存源码信息,只缓存打包后的代码信息,这样分析页面上的代码也将是打包后的。
features types
- 如果你将
features
设置为数组类型,该插件只会开启你在 features
数组中定义的功能。
- 如果你将
features
设置为简单对象类型,该插件只会关闭你在 features
对象中值为 false
的功能。
RsdoctorWebpackPluginFeatures
features
类型如下:
interface RsdoctorWebpackPluginFeatures {
/**
* turn off it if you need not to analyze the executions of webpack loaders.
* @default true
*/
loader?: boolean;
/**
* turn off it if you need not to analyze the executions of webpack plugins.
* @default true
*/
plugins?: boolean;
/**
* turn off it if you need not to analyze the executions of resolver.
* @default false
*/
resolver?: boolean;
/**
* turn off it if you need not to analyze the output bundle.
* @default true
*/
bundle?: boolean;
/**
* turn on it if you just use lite mode. This mode do not have source codes.
* @default false
* @deprecated
*/
lite?: boolean;
}
RsdoctorRspackPluginFeatures
features
类型如下:
interface RsdoctorRspackPluginFeatures {
/**
* turn off it if you need not to analyze the executions of webpack loaders.
* @default true
*/
loader?: boolean;
/**
* turn off it if you need not to analyze the executions of webpack plugins.
* @default true
*/
plugins?: boolean;
/**
* turn off it if you need not to analyze the output bundle.
* @default true
*/
bundle?: boolean;
/**
* turn on it if you just use lite mode. This mode do not have source codes.
* @default false
* @deprecated
*/
lite?: boolean;
}
mode
Version: 0.4.0
- 类型:
normal | brief | lite
- 可选:
true
- 默认值:
normal
选择使用的 Rsdoctor 构建报告模式,有以下几种:
-
normal 模式: 在构建产物目录中生成一个 .rsdoctor
文件夹,其中包含各种数据文件,并在报告页面中展示代码。输出目录可以通过 reportDir 进行配置。
-
brief 模式: 在构建产物目录的 .rsdoctor
文件夹中生成一个 HTML 报告文件,所有构建分析数据会整合注入到这个 HTML 文件中,可以通过浏览器打开该 HTML 文件查看报告。brief 模式还有更多配置项,详细信息请参阅:brief.
-
lite 模式: 基于普通模式,不展示源码和产物代码,仅显示打包后的代码信息。
output
Version: 1.0.0
compressData
- 类型:
boolean
- 可选:
true
- 默认值:
true
compressData 用于配置是否将 [outputDir]/.rsdoctor 下的分析数据进行压缩处理。
reportCodeType
new RsdoctorRspackPlugin({
reportCodeType: { noModuleSource: true } // { noAssetsAndModuleSource: true }
}),
reportDir
- 类型:
string
- 可选:
true
- 默认值:
undefined
Rsdoctor 报告输出目录,默认是构建产物输出目录。
port
- 类型:
number
- 可选:
true
- 默认值:
random(3000, 8999)
配置 Rsdoctor 服务的端口。
reportCodeType [Deprecated]
Deprecated
请看 output.reportCodeType
reportDir [Deprecated]
Deprecated
请看 output.reportDir
supports
该选项是配置 Rsdoctor 是否开启某些细节特性分析能力支持的,例如:是否开启对 BannerPlugin 的兼容能力。
supportsTypes
type ISupport = {
banner?: boolean;
parseBundle?: boolean;
generateTileGraph?: boolean;
};
banner
DANGER
supports.banner
分析仅用于调试,请勿将其用于生产。
如果开启 supports.banner
则会开启 Rsdoctor 对 BannerPlugin 的兼容逻辑。详细请看:支持 BannerPlugin
generateTileGraph
- 默认值: 使用 Rspack 时默认值是
false
,否则为 true
- 类型:
boolean
是否开启生成瓦片图的能力,影响是 Bundle Size 页面中是否有 webpack-bundle-analyzer
的瓦片图。
parseBundle
在部分大型仓库中,反解 Bundle 解析执行耗时过大,这是因为 Parse Bundle 的分析利用了 AST 解析与处理。当产物文件过多时,耗时也会增加。如果不需要此功能,可以通过 supports.parseBundle
配置进行选择性关闭。示例如下:
chain.plugin('Rsdoctor').use(RsdoctorRspackPlugin, [
{
supports: {
parseBundle: false,
},
},
]);
关闭 Parse Bundle 能力只会影响是否能查看到 Bundle 中 Module 的最终打包大小(Bundled Size)及最终打包代码(Bundled Code):