Back to Rspack

Rstack CLI Best Practices

.agents/skills/rstack-cli-best-practices/SKILL.md

2.1.83.6 KB
Original Source

Rstack CLI Best Practices

Rstack CLI is the rstack package, exposed through the rs binaries. It provides one CLI, one config file, and a consistent workflow for the Rstack JavaScript toolchain.

It covers web app, library, docs, test, lint, Git hook, and staged-file workflows.

Commands

Use rs -h for top-level help, and rs <command> -h for command help where supported.

CommandPurposeUnderlying toolConfig
rs devRun the app dev serverRsbuilddefine.app
rs buildBuild the app for productionRsbuilddefine.app
rs previewPreview the app production buildRsbuilddefine.app
rs libBuild a libraryRslibdefine.lib
rs docServe or build docsRspressdefine.doc
rs testRun testsRstestdefine.test
rs lintLint codeRslintdefine.lint
rs setupInstall project-local Git hooksNoneNone
rs stagedRun tasks on staged Git fileslint-stageddefine.staged

Key behavior:

  • Unless define.test already sets extends, rs test extends define.app through @rstest/adapter-rsbuild or falls back to define.lib through @rstest/adapter-rslib. The app config takes precedence when both are defined.
  • rs doc requires the optional @rspress/core dependency.

rstack.config.ts

Rstack CLI loads rstack.config.{ts,js,mts,mjs} by default.

Register config with define.*:

ts
import { define } from 'rstack';

define.app({
  // Rsbuild config for `rs dev`, `rs build`, and `rs preview`
});

define.test({
  // Rstest config for `rs test`
});

Lazy Configuration

Prefer async functions with dynamic imports for dependencies. Avoid top-level sync imports of heavy dependencies in rstack.config.ts.

ts
import { define } from 'rstack';

define.app(async () => {
  const { pluginReact } = await import('@rsbuild/plugin-react');
  return {
    plugins: [pluginReact()],
  };
});

Import Paths

Prefer Rstack-exported paths:

Instead ofPrefer
@rsbuild/corerstack/app
@rslib/corerstack/lib
@rstest/corerstack/test
@rslint/corerstack/lint
@rsbuild/core/typesrstack/types
@rslib/core/typesrstack/types
@rstest/core/globalsrstack/test/globals
@rstest/core/importMetarstack/test/importMeta

Git Hooks

Use rs setup for project-local Git hooks, commonly with rs staged in a pre-commit hook.