agentleFS
rstackjsrstackjs/agent-skills/skills/rslib-best-practices/SKILL.md

rslib-best-practices

Skill97 starsChanged 3 months agoMITView on GitHub

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

We split this skill into the rules it gives an agent

19 rules. About 0 are common, 2 are distinctive, and 17 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 17

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use rslib.config.ts and defineConfig

    line 12
  2. Very specific:

    Check Rslib-specific configurations first (e.g., lib.*), and also leverage Rsbuild configurations (e.g., source.*, output.*, tools.*) as …

    line 13
  3. Very specific:

    Use rslib to build

    line 19
  4. Very specific:

    Use rslib --watch to build in watch mode for local development

    line 20
  5. Very specific:

    Use rslib inspect to inspect final Rslib/Rsbuild/Rspack configs

    line 21
  6. Very specific:

    Prefer to build pure-ESM package with "type": "module" in package.json

    line 25
  7. Very specific:

    Prefer to use bundleless mode with output.target set to 'web' when building component libraries

    line 26
  8. Very specific:

    Prefer to use bundle mode when building Node.js utility libraries

    line 27
  9. Very specific:

    Ensure exports field in package.json is correctly configured and matches the actual JavaScript output and declaration files output of …

    line 28
  10. Very specific:

    Prefer to enable declaration file generation with lib.dts: true or detailed configurations

    line 32
  11. Very specific:

    Prefer to place dependencies to be bundled in devDependencies in bundle mode and dependencies in dependencies and peerDependencies will be …

    line 37
  12. Very specific:

    Verify the build output and dependency specifiers in package.json carefully to ensure no missing dependency errors occur when consumers …

    line 38
  13. Very specific:

    Keep syntax target in lib.syntax aligned with real compatibility requirements to enable better optimizations

    line 42
  14. Distinctive:

    Avoid format-specific APIs in source code for better compatibility with different output formats

    line 43
  15. Distinctive:

    Prefer lightweight dependencies to reduce bundle size

    line 44
  16. Very specific:

    Prefer to use Rstest with @rstest/adapter-rslib for writing tests

    line 48
  17. Very specific:

    Prefer to use Rspress for writing library documentation, with @rspress/plugin-preview and @rspress/plugin-api-docgen for component previews …

    line 49
  18. Very specific:

    Run with DEBUG=rsbuild when diagnosing config resolution or plugin behavior

    line 53
  19. Very specific:

    Read generated files in dist/.rsbuild to confirm final Rsbuild/Rspack config, not assumed config

    line 54

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.