
Rslib Best Practices
- 688 installs
- 86 repo stars
- Updated August 4, 2026
- rstackjs/agent-skills
rslib-best-practices is an agent skill that enforces Rslib configuration, CLI workflow, output formats, and declaration-file patterns for developers who publish reusable JavaScript or TypeScript libraries.
About
rslib-best-practices is a build-time guidance skill for Rslib library projects powered by Rsbuild and Rspack. It instructs agents to use rslib.config.ts with defineConfig, prioritize lib-specific settings, and fall back to Rsbuild source, output, and tools blocks when needed. Advanced cases route through tools.rspack or tools.bundlerChain for native Rspack configuration. Developers reach for rslib-best-practices when writing, reviewing, or troubleshooting Rslib configs, dependency handling, build optimization, and .d.ts declaration output for npm-ready packages.
- Configuration rules covering rslib.config.ts, defineConfig, Rsbuild/Rspack fallbacks, and tsconfig path aliases
- CLI workflow with rslib build, rslib --watch, and rslib inspect commands
- Output guidance preferring pure-ESM, bundleless for components, bundle for Node utilities, and correct exports field
- Declaration file generation with lib.dts options and matching JavaScript output
- Dependency handling, build optimization, and toolchain integration best practices
Rslib Best Practices by the numbers
- 688 all-time installs (skills.sh)
- +20 installs in the week ending Jul 26, 2026 (Skillselion tracking)
- Ranked #1,433 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/rstackjs/agent-skills --skill rslib-best-practicesAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 688 |
|---|---|
| repo stars | ★ 86 |
| Last updated | August 4, 2026 |
| Repository | rstackjs/agent-skills ↗ |
How do you configure Rslib for library builds?
Ensure Rslib configuration, output formats, declaration files, and CLI usage follow recommended patterns when creating reusable JavaScript or TypeScript libraries.
Who is it for?
Developers authoring or reviewing reusable JavaScript or TypeScript npm libraries with Rslib, Rsbuild, and Rspack.
Skip if: Application-only Rsbuild projects, non-Rslib bundlers like Vite or webpack without Rslib, or teams not publishing library packages.
When should I use this skill?
An agent is writing, reviewing, or debugging rslib.config.ts, lib output, declaration files, or Rslib CLI commands for a library repo.
What you get
Validated rslib.config.ts, optimized lib output targets, correct declaration files, and Rsbuild/Rspack toolchain settings aligned with Rslib conventions.
- rslib.config.ts
- library build output
- TypeScript declaration files
Files
Rslib Best Practices
Apply these rules when writing or reviewing Rslib library projects.
Configuration
- Use
rslib.config.tsanddefineConfig - Check Rslib-specific configurations first (e.g.,
lib.*), and also leverage Rsbuild configurations (e.g.,source.*,output.*,tools.*) as needed - For deep-level or advanced configuration needs, use
tools.rspackortools.bundlerChainto access Rspack's native configurations - In TypeScript projects, prefer
tsconfig.jsonpath aliases
CLI
- Use
rslibto build - Use
rslib --watchto build in watch mode for local development - Use
rslib inspectto inspect final Rslib/Rsbuild/Rspack configs
Output
- Prefer to build pure-ESM package with
"type": "module"inpackage.json - Prefer to use bundleless mode with
output.targetset to'web'when building component libraries - Prefer to use bundle mode when building Node.js utility libraries
- Ensure
exportsfield inpackage.jsonis correctly configured and matches the actual JavaScript output and declaration files output of different formats (ESM, CJS, etc.)
Declaration files
- Prefer to enable declaration file generation with
lib.dts: trueor detailed configurations - For faster type generation, enable
lib.dts.tsgoexperimental feature with@typescript/native-previewinstalled
Dependencies
- Prefer to place dependencies to be bundled in
devDependenciesin bundle mode and dependencies independenciesandpeerDependencieswill be automatically externalized (not bundled) by default - Verify the build output and dependency specifiers in
package.jsoncarefully to ensure no missing dependency errors occur when consumers install and use this package
Build optimization
- Keep syntax target in
lib.syntaxaligned with real compatibility requirements to enable better optimizations - Avoid format-specific APIs in source code for better compatibility with different output formats
- Prefer lightweight dependencies to reduce bundle size
Toolchain integration
- Prefer to use Rstest with
@rstest/adapter-rslibfor writing tests - Prefer to use Rspress for writing library documentation, with
@rspress/plugin-previewand@rspress/plugin-api-docgenfor component previews and API docs
Debugging
- Run with
DEBUG=rsbuildwhen diagnosing config resolution or plugin behavior - Read generated files in
dist/.rsbuildto confirm final Rsbuild/Rspack config, not assumed config
Documentation
- For the latest Rslib docs, read https://rslib.rs/llms.txt
Related skills
How it compares
Choose rslib-best-practices when publishing libraries with Rslib rather than generic bundler skills that target application builds only.
FAQ
What config file does Rslib use?
Rslib projects use rslib.config.ts with defineConfig as the primary entry point. The rslib-best-practices skill checks lib-specific settings first, then leverages Rsbuild configuration blocks such as source, output, and tools when deeper control is needed.
How do you access native Rspack options in Rslib?
rslib-best-practices directs developers to tools.rspack or tools.bundlerChain inside rslib.config.ts for advanced bundler configuration. These hooks expose Rspack-native settings without abandoning the Rslib and Rsbuild toolchain.