Skip to main content
skill CX Codex

rspack-best-practices — Claude Code skill: setup and rules

Ruleset for configuring, troubleshooting, and profiling Rspack builds. Helps coding agents apply native loaders and optimize bundle performance.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a claude-code
Open on GitHub

What rspack-best-practices does

This skill guides coding agents through creating and reviewing rspack.config.ts. It directs the model to apply defineConfig, keep loader rules narrow with explicit conditions, and favor native Rspack loaders over community JavaScript packages.

The instructions cover type checking, asset management, and CSS processing. The assistant configures built-in CSS modules, integrates @tailwindcss/webpack or builtin:lightningcss-loader, and drops legacy tools like file-loader. For performance bottlenecks, it suggests tracing compiler phases with RSPACK_PROFILE=OVERVIEW or analyzing CPU profiles with --cpu-prof.

Keeping legacy tools like babel-loader or terser removes most speed gains from Rspack. The skill also enforces security by preventing .map file deployment to public servers when production source maps are active.

What it helps with

  • configure rspack.config.ts using native loaders
  • migrate legacy Webpack rules to Rspack asset modules
  • integrate CSS processing with builtin:lightningcss-loader
  • debug slow build steps with RSPACK_PROFILE=OVERVIEW

Example prompts for the agent

  • Review my rspack.config.ts and replace slow loaders with native alternatives
  • Set up TypeScript type checking with ts-checker-rspack-plugin
  • Profile our Rspack build bottlenecks and suggest optimizations

How to install rspack-best-practices

1Skills CLI (Vercel)

npx skills add rstackjs/agent-skills --skill rspack-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/rspack-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/rspack-best-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about rspack-best-practices

How to install rspack-best-practices in Claude Code?

Run npx skills add rstackjs/agent-skills --skill rspack-best-practices -a claude-code. This installs the file into ~/.claude/skills/rspack-best-practices/SKILL.md.

What does rspack-best-practices do?

It teaches coding assistants proven patterns for Rspack configuration. The agent prioritizes built-in plugins, sets up asset modules, and enforces safe production source map handling.

Which profiling methods does this skill recommend?

It recommends Node CPU profiling via --cpu-prof for JavaScript overhead. For bottlenecks inside the compiler itself, it guides the agent to use RSPACK_PROFILE=OVERVIEW.

Source text

SKILL.md · MIT
---
name: rspack-best-practices
description: Configure, review, or troubleshoot Rspack builds, including loaders, CSS, assets, type checking, bundle optimization, and profiling.
---

# Rspack best practices

Apply these rules when writing or reviewing Rspack projects.

## Configuration

- Use `rspack.config.ts` and `defineConfig`
- Define explicit `entry` values for multi-page applications
- Keep one main config and branch by `process.env.NODE_ENV` only when needed
- Keep rule conditions narrow and explicit (`test`, `include`, `exclude`, `resourceQuery`)
- Prefer built-in Rspack plugins/loaders over community JS alternatives when equivalent features exist

## CLI

If `@rspack/cli` is installed:

- Use `rspack dev` for local development
- Use `rspack build` for production build
- Use `rspack preview` only for local production preview

## Type checking

- Use `ts-checker-rspack-plugin` for integrated dev/build type checks
- Or run `tsc --noEmit`/`vue-tsc --noEmit` as an explicit script step

## CSS

Choose one strategy:

- Built-in CSS (`type: 'css' | 'css/auto' | 'css/module'`) for modern setups
- `css-loader` + `CssExtractRspackPlugin` for webpack migration compatibility
- `style-loader` for pure style-in-JS runtime injection scenarios

Optional:

- Use `builtin:lightningcss-loader` when goals are syntax downgrade + vendor prefixing
- Use `sass-loader`/`less-loader` for preprocessing Sass/Less files
- Use `@tailwindcss/webpack` for Tailwind CSS integration

## Bundle size optimization

- Prefer dynamic `import()` for non-critical code paths
- Prefer lightweight libraries where possible
- Keep `target` aligned with real compatibility requirements

## Asset management

- Import source-managed assets from project source directories, not from `public`
- Reference `public` files by absolute URL path
- Prefer asset modules (`asset`, `asset/resource`, `asset/inline`, `asset/source`) over legacy `file-loader`/`url-loader`/`raw-loader`

## Profiling

- Use Node CPU profiling (`--cpu-prof`) when JavaScript-side overhead is suspected
- Use `RSPACK_PROFILE=OVERVIEW` and analyze trace output for compiler-phase bottlenecks
- Replace known slow stacks first (`babel-loader`, PostCSS, terser) with Rspack built-ins when feasible

## Security

- Do not publish `.map` files to public servers/CDNs when production source maps are enabled

## Documentation

- For the latest (v2) docs, read http://rspack.rs/llms.txt
- For Rspack v1 docs, read http://v1.rspack.rs/llms.txt

© rstackjs · MIT · rstackjs/agent-skills

Similar skills

Everything for Frontend and UI →

From the same set13

rsbuild-best-practices Provides rules for configuring, reviewing, and troubleshooting Rsbuild applications. Helps agents inspect builds, handle assets, and profile performance. CX Codex +1 2,700installs rstest-best-practices Rules for setting up and writing Rstest tests: environments, mocks, snapshots, coverage and CI. Useful when a package moves to Rstest or its tests have drifted apart. CX Codex +1 1,400installs rslib-best-practices Provides guidelines for building JavaScript and TypeScript libraries with Rslib. Useful when configuring outputs, declaration files, and dependency bundling. CX Codex +1 1,000installs rspress-best-practices A skill that gives the agent rules for Rspress v2 sites: config, navigation, MDX, assets, search and deployment. Useful once the docs exist and the agent edits them. CX Codex +1 538installs rspack-v2-upgrade Walks a Rspack 1.x project through the v2 upgrade: dependencies, config, build checks. Useful when a major bump is too fiddly to do by hand. CX Codex +1 515installs rspress-description-generator A skill that fills in the description frontmatter field on Rspress pages that lack one. Useful when the docs site has grown and meta descriptions are missing in places. CX Codex +1 498installs rsbuild-v2-upgrade Walks a Rsbuild 1.x project through the v2 migration: dependencies, config, breaking options. Useful when a major bump would otherwise eat an evening. CX Codex +1 476installs rsdoctor-analysis Evaluates Rspack and Webpack bundles from a local rsdoctor-data.json report. It ranks package duplicates, heavy modules, and tree-shaking leaks. CX Codex +1 450installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor