$npx -y skills add rstackjs/agent-skills --skill rsbuild-best-practicesRsbuild best practices for config, CLI workflow, type checking, bundle optimization, assets, and debugging. Use when writing, reviewing, or troubleshooting Rsbuild projects.
| 1 | # Rsbuild Best Practices |
| 2 | |
| 3 | Apply these rules when writing or reviewing Rsbuild projects. |
| 4 | |
| 5 | ## Configuration |
| 6 | |
| 7 | - Use `rsbuild.config.ts` and `defineConfig` |
| 8 | - Use `tools.rspack` or `tools.bundlerChain` only when no first-class Rsbuild option exists |
| 9 | - Define explicit `source.entry` values for multi-page applications |
| 10 | - In TypeScript projects, prefer `tsconfig.json` path aliases first |
| 11 | |
| 12 | ## CLI |
| 13 | |
| 14 | - Use `rsbuild` for local development |
| 15 | - Use `rsbuild build` for production build |
| 16 | - Use `rsbuild preview` only for local production preview |
| 17 | - Use `rsbuild inspect` to inspect final Rsbuild/Rspack configs |
| 18 | |
| 19 | ## Type checking |
| 20 | |
| 21 | - Use `@rsbuild/plugin-type-check` for integrated dev/build type checks |
| 22 | - Or run `tsc --noEmit`/`vue-tsc --noEmit` as an explicit script step |
| 23 | |
| 24 | ## Bundle size optimization |
| 25 | |
| 26 | - Prefer dynamic `import()` for non-critical code paths |
| 27 | - Prefer lightweight libraries where possible |
| 28 | - Keep browserslist aligned with real compatibility requirements |
| 29 | |
| 30 | ## Asset management |
| 31 | |
| 32 | - Import source-managed assets from project source directories, not from `public` |
| 33 | - Reference `public` files by absolute URL path |
| 34 | |
| 35 | ## Security |
| 36 | |
| 37 | - Do not publish `.map` files to public servers/CDNs when production source maps are enabled |
| 38 | |
| 39 | ## Debugging |
| 40 | |
| 41 | - Run with `DEBUG=rsbuild` when diagnosing config resolution or plugin behavior |
| 42 | - Read generated files in `dist/.rsbuild` to confirm final config, not assumed config |
| 43 | |
| 44 | ## Profiling |
| 45 | |
| 46 | - Use Node CPU profiling (`--cpu-prof`) when JavaScript-side overhead is suspected |
| 47 | - Use `RSPACK_PROFILE=OVERVIEW` and analyze trace output for compiler-phase bottlenecks |
| 48 | |
| 49 | ## Documentation |
| 50 | |
| 51 | - For the latest (v2) docs, read http://rsbuild.rs/llms.txt |
| 52 | - For Rsbuild v1 docs, read http://v1.rsbuild.rs/llms.txt |