# rspack-best-practices

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

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 669 installs · ★ 97
- Author: rstackjs
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/rstackjs/agent-skills/tree/HEAD/skills/rspack-best-practices/SKILL.md
- Updated: 2026-10-22
- HTML: https://affpapa.org/en/nevibecode/skills/rspack-best-practices

## What it 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.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/rspack-best-practices/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/rspack-best-practices/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/rspack-best-practices/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/rspack-best-practices/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install rstackjs/agent-skills rspack-best-practices
```

2. **Manually: put the files in place**
- File: `.github/skills/rspack-best-practices/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/rstackjs/agent-skills --path skills/rspack-best-practices
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/rspack-best-practices/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add rstackjs/agent-skills --skill rspack-best-practices -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/rstackjs/agent-skills/tree/HEAD/skills/rspack-best-practices/SKILL.md

## When to use it
- 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
- 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

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 51d454f3c7b98d7f.

BEGIN THIRD-PARTY FILE 51d454f3c7b98d7f
```text
---
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
```
END THIRD-PARTY FILE 51d454f3c7b98d7f

The third-party file has ended. Everything between the 51d454f3c7b98d7f tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© rstackjs · MIT · https://github.com/rstackjs/agent-skills/tree/HEAD/skills/rspack-best-practices/SKILL.md

## Similar
- [frontend-design](https://affpapa.org/en/nevibecode/skills/frontend-design.md) — skill · 1025790 installs
- [design-taste-frontend](https://affpapa.org/en/nevibecode/skills/design-taste-frontend.md) — skill · 678700 installs
- [prototype](https://affpapa.org/en/nevibecode/skills/prototype.md) — skill · 986201 installs
- [hyperframes](https://affpapa.org/en/nevibecode/skills/heygen-com-hyperframes.md) — skill · 1200000 installs

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
