$npx -y skills add vercel/next.js --skill next-rspackMaintain @next/rspack-core and @next/rspack-binding packages. Use when editing rspack/package.json, rspack/crates/binding/Cargo.toml, rspack/rust-toolchain.toml, or packages/next-rspack/package.json. Covers upgrading @rspack/core npm version, rspack_* crate versions, Rust toolcha
| 1 | # Next.js with Rspack |
| 2 | |
| 3 | ## When to Use |
| 4 | |
| 5 | Use this skill when you need to: |
| 6 | |
| 7 | - Upgrade `@rspack/core` npm package version |
| 8 | - Upgrade rspack crate dependency versions |
| 9 | - Upgrade Rust version in `rspack/rust-toolchain.toml` (rspack directory only) |
| 10 | - Fix Rspack-related compilation issues |
| 11 | - Develop Rspack-specific features in Next.js |
| 12 | |
| 13 | > **⚠️ Scope Limitation**: This skill only applies to code and configuration under the `rspack/` directory. The `rust-toolchain.toml` in the repository root is for Turbopack and is outside the scope of this skill. |
| 14 | |
| 15 | ## Architecture Overview |
| 16 | |
| 17 | ### Package Structure |
| 18 | |
| 19 | ``` |
| 20 | rspack/ # Independent workspace (separate rust toolchain and npm releases) |
| 21 | ├── Cargo.toml # Rust workspace configuration |
| 22 | ├── rust-toolchain.toml # Rust version configuration |
| 23 | ├── package.json # @next/rspack-core package definition |
| 24 | ├── lib/ |
| 25 | │ ├── index.js # Exports @rspack/core + custom plugins |
| 26 | │ └── index.d.ts # Type definitions |
| 27 | └── crates/ |
| 28 | └── binding/ |
| 29 | ├── Cargo.toml # Rust crate dependencies (rspack_* crates) |
| 30 | └── package.json # @next/rspack-binding package definition |
| 31 | |
| 32 | packages/ |
| 33 | └── next-rspack/ |
| 34 | └── package.json # References @next/rspack-core |
| 35 | ``` |
| 36 | |
| 37 | ### Dependency Graph |
| 38 | |
| 39 | ``` |
| 40 | packages/next-rspack |
| 41 | └── @next/rspack-core (rspack/package.json) |
| 42 | ├── @rspack/core (npm dependency) |
| 43 | └── @next/rspack-binding (rspack/crates/binding) |
| 44 | └── rspack_* crates (Cargo.toml dependencies) |
| 45 | ``` |
| 46 | |
| 47 | ### Version Mapping Rules |
| 48 | |
| 49 | | @rspack/core npm version | rspack crate version | Notes | |
| 50 | | ------------------------ | -------------------- | ------------------------------------------------- | |
| 51 | | `2.0.0-rc.0` | `0.100.0-rc.0` | npm major.minor maps to crate 0.(major\*50+minor) | |
| 52 | | `1.3.x` | `0.53.x` | e.g., 1.3 → 0.53 | |
| 53 | | `1.2.x` | `0.52.x` | e.g., 1.2 → 0.52 | |
| 54 | |
| 55 | ## Upgrade Process |
| 56 | |
| 57 | ### Step 1: Get Upstream Version Information |
| 58 | |
| 59 | Query https://github.com/web-infra-dev/rspack to obtain: |
| 60 | |
| 61 | - Target `@rspack/core` npm version |
| 62 | - Corresponding rspack crate version |
| 63 | - Rust channel version from `rust-toolchain.toml` |
| 64 | |
| 65 | ### Step 2: Update npm Dependencies |
| 66 | |
| 67 | Edit `rspack/package.json`: |
| 68 | |
| 69 | ```json |
| 70 | { |
| 71 | "dependencies": { |
| 72 | "@rspack/core": "<new version>", |
| 73 | "@next/rspack-binding": "workspace:*" |
| 74 | } |
| 75 | } |
| 76 | ``` |
| 77 | |
| 78 | ### Step 3: Update Cargo.toml |
| 79 | |
| 80 | Edit `rspack/crates/binding/Cargo.toml`, update all rspack crate versions: |
| 81 | |
| 82 | ```toml |
| 83 | [dependencies] |
| 84 | rspack_binding_builder = { version = "=<new crate version>" } |
| 85 | rspack_binding_builder_macros = { version = "=<new crate version>" } |
| 86 | rspack_core = { version = "=<new crate version>" } |
| 87 | rspack_error = { version = "=<new crate version>" } |
| 88 | rspack_hook = { version = "=<new crate version>" } |
| 89 | rspack_plugin_externals = { version = "=<new crate version>" } |
| 90 | rspack_regex = { version = "=<new crate version>" } |
| 91 | # rspack_sources version is managed separately, may not follow the main version |
| 92 | |
| 93 | [target.'cfg(...)'.dependencies] |
| 94 | rspack_binding_builder = { version = "=<new crate version>", features = ["plugin"] } |
| 95 | |
| 96 | [build-dependencies] |
| 97 | rspack_binding_build = { version = "=<new crate version>" } |
| 98 | ``` |
| 99 | |
| 100 | ### Step 4: Update Rust Toolchain |
| 101 | |
| 102 | Edit `rspack/rust-toolchain.toml`: |
| 103 | |
| 104 | ```toml |
| 105 | [toolchain] |
| 106 | profile = "default" |
| 107 | components = ["rust-src"] |
| 108 | channel = "<nightly version matching upstream rspack>" |
| 109 | ``` |
| 110 | |
| 111 | ### Step 5: Verify Build |
| 112 | |
| 113 | ```bash |
| 114 | # Execute in rspack directory |
| 115 | cd rspack |
| 116 | |
| 117 | # Check Rust code |
| 118 | cargo check |
| 119 | |
| 120 | # Build binding (requires Rust installed) |
| 121 | pnpm build |
| 122 | ``` |
| 123 | |
| 124 | ### Step 6: Link to packages/next-rspack |
| 125 | |
| 126 | `rspack/` is an independent workspace not included in the root pnpm-workspace, manual linking is required: |
| 127 | |
| 128 | ```bash |
| 129 | # Execute from repository root |
| 130 | cd packages/next-rspack |
| 131 | |
| 132 | # Link locally built @next/rspack-core |
| 133 | pnpm link ../../rspack |
| 134 | ``` |
| 135 | |
| 136 | Or modify `packages/next-rspack/package.json` to use local path (for local testing only, do not commit): |
| 137 | |
| 138 | ```json |
| 139 | { |
| 140 | "dependencies": { |
| 141 | "@next/rspack-core": "link:../../rspack" |
| 142 | } |
| 143 | } |
| 144 | ``` |
| 145 | |
| 146 | > **Important**: After linking, run `pnpm install` in the root directory to update dependency relationships. |
| 147 | |
| 148 | ### Step 7: Run Tests |
| 149 | |
| 150 | ```bash |
| 151 | # Execute from repository root |
| 152 | pnpm test-r |