Rslib Best Practices

by rstackjs2966acbef746No license95 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated today

Configure, review, or troubleshoot Rslib library builds, output formats, declarations, dependency handling, and integrations.

Instructions onlySoftware Development
AI-generated overview

Rules for configuring, reviewing and troubleshooting Rslib library builds, output formats, declarations and dependencies.

What it does
Provides a checklist of best practices for Rslib library projects, covering configuration files and CLI commands, output format and exports setup, declaration file generation, dependency placement and externalization, build optimization, toolchain integration and debugging. It is guidance only and produces no files or scripts itself.
When to use it
Use when writing or reviewing an Rslib library project, or when diagnosing build, output format, declaration or dependency problems in one. Also useful when choosing between bundle and bundleless modes or integrating testing and documentation tooling.
Requirements
No scripts or bundled assets; the agent only needs the skill instructions. Following the guidance assumes a project using Rslib, Rsbuild, Rspack, TypeScript and optionally @typescript/native-preview, @rstest/adapter-rslib and Rspress. Network access is needed only to read the linked Rslib documentation.

Rslib best practices

Apply these rules when writing or reviewing Rslib library projects.

Configuration

  • Use rslib.config.ts and defineConfig
  • 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.rspack or tools.bundlerChain to access Rspack's native configurations
  • In TypeScript projects, prefer tsconfig.json path aliases

CLI

  • Use rslib to build
  • Use rslib --watch to build in watch mode for local development
  • Use rslib inspect to inspect final Rslib/Rsbuild/Rspack configs

Output

  • Prefer to build pure-ESM package with "type": "module" in package.json
  • Prefer to use bundleless mode with output.target set to 'web' when building component libraries
  • Prefer to use bundle mode when building Node.js utility libraries
  • 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.)

Declaration files

  • Prefer to enable declaration file generation with lib.dts: true or detailed configurations
  • For faster type generation, enable lib.dts.tsgo experimental feature with @typescript/native-preview installed

Dependencies

  • 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
  • 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

Build optimization

  • Keep syntax target in lib.syntax aligned 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-rslib for writing tests
  • Prefer to use Rspress for writing library documentation, with @rspress/plugin-preview and @rspress/plugin-api-docgen for component previews and API docs

Debugging

  • Run with DEBUG=rsbuild when diagnosing config resolution or plugin behavior
  • Read generated files in dist/.rsbuild to confirm final Rsbuild/Rspack config, not assumed config

Documentation

Source and attribution

Source:rstackjs/agent-skillsinskills/rslib-best-practicesat commit2966acb

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

Rslib Best Practices Agent Skill | SourceWeft