Rslib Best Practices

rstackjs/agent-skills/skills/rslib-best-practices

作者 rstackjs2966acbef746無授權條款95 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

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

AI 產生的概覽

用於設定、審查與排解 Rslib 函式庫建置、輸出格式、宣告檔與相依性的規則。

功能
提供 Rslib 函式庫專案的最佳實務清單,涵蓋設定檔與命令列指令、輸出格式與 exports 設定、宣告檔產生、相依性放置與外部化、建置最佳化、工具鏈整合以及除錯。它僅提供指引,本身不產生檔案或指令碼。
適用情境
在撰寫或審查 Rslib 函式庫專案時使用,或在排解其建置、輸出格式、宣告檔或相依性問題時使用。也適用於在 bundle 與 bundleless 模式之間做選擇,或整合測試與文件工具時。
執行需求
不含指令碼或附帶資源,代理只需技能說明。套用這些建議的前提是專案使用 Rslib、Rsbuild、Rspack、TypeScript,並可選用 @typescript/native-preview、@rstest/adapter-rslib 與 Rspress。僅在閱讀所連結的 Rslib 文件時需要網路存取。

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

來源與署名

來源:rstackjs/agent-skills位於skills/rslib-best-practices提交2966acb

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架