rsbuild-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRsbuild Best Practices
Rsbuild最佳实践
Apply these rules when writing or reviewing Rsbuild projects.
在编写或评审Rsbuild项目时请遵循以下规则:
Configuration
配置
- Use and
rsbuild.config.tsdefineConfig - Use or
tools.rspackonly when no first-class Rsbuild option existstools.bundlerChain - Define explicit values for multi-page applications
source.entry - In TypeScript projects, prefer path aliases first
tsconfig.json
- 使用和
rsbuild.config.tsdefineConfig - 仅当没有原生Rsbuild配置选项可用时,才使用或
tools.rspacktools.bundlerChain - 多页应用请显式定义值
source.entry - TypeScript项目优先使用中的路径别名
tsconfig.json
CLI
CLI
- Use for local development
rsbuild dev - Use for production build
rsbuild build - Use only for local production preview
rsbuild preview - Use to inspect final Rsbuild/Rspack configs
rsbuild inspect
- 本地开发使用
rsbuild dev - 生产环境构建使用
rsbuild build - 仅在本地预览生产构建结果时使用
rsbuild preview - 使用查看最终的Rsbuild/Rspack配置
rsbuild inspect
Type checking
类型检查
- Use for integrated dev/build type checks
@rsbuild/plugin-type-check - Or run /
tsc --noEmitas an explicit script stepvue-tsc --noEmit
- 使用实现开发/构建流程集成的类型检查
@rsbuild/plugin-type-check - 或者将/
tsc --noEmit作为独立的脚本步骤运行vue-tsc --noEmit
Bundle size optimization
打包体积优化
- Prefer dynamic for non-critical code paths
import() - Prefer lightweight libraries where possible
- Keep browserslist aligned with real compatibility requirements
- 非核心代码路径优先使用动态
import() - 尽可能选择轻量级第三方库
- 保持browserslist配置与实际兼容性要求一致
Asset management
资源管理
- Import source-managed assets from project source directories, not from
public - Reference files by absolute URL path
public
- 项目源码目录中自行管理的资源请通过import引入,不要放在目录
public - 引用目录下的文件请使用绝对URL路径
public
Security
安全
- Do not publish files to public servers/CDNs when production source maps are enabled
.map
- 生产环境启用source map时,不要将文件发布到公共服务器/CDN
.map
Debugging
调试
- Run with when diagnosing config resolution or plugin behavior
DEBUG=rsbuild - Read generated files in to confirm final config, not assumed config
dist/.rsbuild
- 排查配置解析或插件行为问题时,添加参数运行
DEBUG=rsbuild - 查看目录下生成的文件确认最终配置,不要依赖假设的配置
dist/.rsbuild
Profiling
性能分析
- Use Node CPU profiling () when JavaScript-side overhead is suspected
--cpu-prof - Use and analyze trace output for compiler-phase bottlenecks
RSPACK_PROFILE=OVERVIEW
- 怀疑JavaScript侧存在性能开销时,使用Node CPU profiling()分析
--cpu-prof - 使用并分析追踪输出来定位编译阶段的瓶颈
RSPACK_PROFILE=OVERVIEW
Documentation
文档
- For the latest (v2) docs, read http://rsbuild.rs/llms.txt
- For Rsbuild v1 docs, read http://v1.rsbuild.rs/llms.txt
- 最新版本(v2)文档请查看http://rsbuild.rs/llms.txt
- Rsbuild v1版本文档请查看http://v1.rsbuild.rs/llms.txt