$npx -y skills add rstackjs/agent-skills --skill rslib-best-practicesRslib best practices for config, CLI workflow, output, declaration files, dependency handling, build optimization and toolchain integration. Use when writing, reviewing, or troubleshooting Rslib projects.
| 1 | # Rslib Best Practices |
| 2 | |
| 3 | Apply these rules when writing or reviewing Rslib library projects. |
| 4 | |
| 5 | ## Configuration |
| 6 | |
| 7 | - Use `rslib.config.ts` and `defineConfig` |
| 8 | - Check Rslib-specific configurations first (e.g., `lib.*`), and also leverage Rsbuild configurations (e.g., `source.*`, `output.*`, `tools.*`) as needed |
| 9 | - For deep-level or advanced configuration needs, use `tools.rspack` or `tools.bundlerChain` to access Rspack's native configurations |
| 10 | - In TypeScript projects, prefer `tsconfig.json` path aliases |
| 11 | |
| 12 | ## CLI |
| 13 | |
| 14 | - Use `rslib` to build |
| 15 | - Use `rslib --watch` to build in watch mode for local development |
| 16 | - Use `rslib inspect` to inspect final Rslib/Rsbuild/Rspack configs |
| 17 | |
| 18 | ## Output |
| 19 | |
| 20 | - Prefer to build pure-ESM package with `"type": "module"` in `package.json` |
| 21 | - Prefer to use bundleless mode with `output.target` set to `'web'` when building component libraries |
| 22 | - Prefer to use bundle mode when building Node.js utility libraries |
| 23 | - Ensure `exports` field in `package.json` is correctly configured and matches the actual JavaScript output and declaration files output of different formats (ESM, CJS, etc.) |
| 24 | |
| 25 | ## Declaration files |
| 26 | |
| 27 | - Prefer to enable declaration file generation with `lib.dts: true` or detailed configurations |
| 28 | - For faster type generation, enable `lib.dts.tsgo` experimental feature with `@typescript/native-preview` installed |
| 29 | |
| 30 | ## Dependencies |
| 31 | |
| 32 | - Prefer to place dependencies to be bundled in `devDependencies` in bundle mode and dependencies in `dependencies` and `peerDependencies` will be automatically externalized (not bundled) by default |
| 33 | - Verify the build output and dependency specifiers in `package.json` carefully to ensure no missing dependency errors occur when consumers install and use this package |
| 34 | |
| 35 | ## Build optimization |
| 36 | |
| 37 | - Keep syntax target in `lib.syntax` aligned with real compatibility requirements to enable better optimizations |
| 38 | - Avoid format-specific APIs in source code for better compatibility with different output formats |
| 39 | - Prefer lightweight dependencies to reduce bundle size |
| 40 | |
| 41 | ## Toolchain integration |
| 42 | |
| 43 | - Prefer to use Rstest with `@rstest/adapter-rslib` for writing tests |
| 44 | - Prefer to use Rspress for writing library documentation, with `@rspress/plugin-preview` and `@rspress/plugin-api-docgen` for component previews and API docs |
| 45 | |
| 46 | ## Debugging |
| 47 | |
| 48 | - Run with `DEBUG=rsbuild` when diagnosing config resolution or plugin behavior |
| 49 | - Read generated files in `dist/.rsbuild` to confirm final Rsbuild/Rspack config, not assumed config |
| 50 | |
| 51 | ## Documentation |
| 52 | |
| 53 | - For the latest Rslib docs, read https://rslib.rs/llms.txt |