Skip to content

feat: add rsbuild adapter#608

Open
yslpn wants to merge 5 commits into
unjs:mainfrom
yslpn:feat/rsbuild-adapter
Open

feat: add rsbuild adapter#608
yslpn wants to merge 5 commits into
unjs:mainfrom
yslpn:feat/rsbuild-adapter

Conversation

@yslpn

@yslpn yslpn commented Jun 14, 2026

Copy link
Copy Markdown

Summary

Closes #607

  • Adds first-class Rsbuild support via createUnplugin(...).rsbuild and createRsbuildPlugin.
  • Reuses the existing Rspack adapter internally through Rsbuild's modifyRspackConfig hook.
  • Updates public types, docs, fixtures, and version metadata coverage for Rsbuild.
  • Exposes meta.versions.rsbuild and the underlying meta.versions.rspack.

Tests

  • pnpm typecheck
  • pnpm test:build
  • pnpm vitest run
  • pnpm build

Summary by CodeRabbit

  • New Features

    • Added Rsbuild as a supported build tool alongside Vite, Webpack, Rollup, esbuild, and Rspack, including a dedicated Rsbuild plugin entry and framework typing.
  • Documentation

    • Updated the homepage, README, and the guide with Rsbuild support, examples, compatibility tables, and visual/icon assets.
  • Tests

    • Added Rsbuild coverage across fixtures and framework/version/unit tests to validate hook order and virtual-module behavior.
  • Chores

    • Updated workspace/dependency and build/test tooling for Rsbuild support.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d0efae3e-8012-48f4-b1f0-f0816c718c74

📥 Commits

Reviewing files that changed from the base of the PR and between 3100900 and f543312.

📒 Files selected for processing (3)
  • package.json
  • src/rsbuild/index.ts
  • src/rspack/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/rsbuild/index.ts

📝 Walkthrough

Walkthrough

Adds a first-class Rsbuild adapter to unplugin. This includes new type definitions for the Rsbuild framework, a refactored rspack hook-wiring routine (applyRspackPlugins / getRspackPluginFromRaw), a new src/rsbuild/index.ts adapter, createRsbuildPlugin and createUnplugin().rsbuild public API, fixture configs, unit tests, and documentation updates.

Changes

Rsbuild First-Class Adapter

Layer / File(s) Summary
Rsbuild type definitions and dependency declarations
src/types.ts, package.json, pnpm-workspace.yaml, tsdown.config.ts
Imports and re-exports RsbuildPlugin from @rsbuild/core, adds rsbuild field to UnpluginOptions, extends UnpluginInstance with an rsbuild factory output, adds 'rsbuild' to SupportedFramework, and adds a framework: 'rsbuild' discriminated union branch to UnpluginContextMeta. Declares @rsbuild/core as a dev/peer dependency and adds it to the bundler's neverBundle list.
Rspack hook extraction and getRspackPluginFromRaw
src/rspack/index.ts
Extracts inline hook wiring from getRspackPlugin().apply() into a shared internal applyRspackPlugins function that centralizes resolve/load/transform/build hook registration. Adds exported getRspackPluginFromRaw helper to create rspack plugins directly from raw plugin arrays and metadata, enabling reuse by the Rsbuild adapter. Avoids mutating incoming rawPlugin objects by creating new resolved options objects.
Rsbuild plugin adapter
src/rsbuild/index.ts
New file exporting getRsbuildPlugin. Initializes rsbuild framework metadata, invokes the unplugin factory, normalizes output to an array, and maps each raw plugin through toRsbuildPlugin. Each plugin's setup(api) populates meta.versions.rsbuild from the runtime version, injects the rspack plugin via api.modifyRspackConfig using getRspackPluginFromRaw, and delegates to optional rsbuildOptions.setup(api).
Public API wiring
src/define.ts
Wires getRsbuildPlugin into the createUnplugin() return as a get rsbuild() getter and exports createRsbuildPlugin as a top-level factory helper, matching the ergonomics of createVitePlugin, createWebpackPlugin, and other bundler adapters.
Unit tests, fixture configs, and build script
test/unit-tests/utils.ts, test/unit-tests/framework-version/index.test.ts, test/fixtures/load/rsbuild.config.mjs, test/fixtures/transform/rsbuild.config.mjs, test/fixtures/virtual-module/rsbuild.config.mjs, test/fixtures/*/__test__/build.test.ts, scripts/buildFixtures.ts
Adds rsbuildBuild test helper and build.rsbuild entry to test utils. Creates Rsbuild fixture configs for load, transform, and virtual-module scenarios with corresponding build test assertions verifying hook execution and output correctness. Introduces comprehensive unit tests covering version metadata population, hook isolation, nested plugin apply semantics, and framework discrimination. Extends fixture build script with rsbuild build steps.
Documentation and docs-site
README.md, docs/index.md, docs/guide/index.md, docs/vite.config.ts, docs/.vitepress/theme/style.css
Adds Rsbuild to supported tools lists, compatibility tables, usage/plugin examples, and homepage feature card with icon asset. Updates docs vite config to include custom icon mapping for Rsbuild. Replaces the rspack-specific feature image margin rule with a generic feature image sizing rule.

Sequence Diagram(s)

sequenceDiagram
  participant PluginAuthor
  participant createRsbuildPlugin
  participant getRsbuildPlugin
  participant toRsbuildPlugin
  participant RsbuildAPI
  participant getRspackPluginFromRaw

  PluginAuthor->>createRsbuildPlugin: UnpluginFactory
  createRsbuildPlugin->>getRsbuildPlugin: factory
  getRsbuildPlugin->>getRsbuildPlugin: build meta {framework:'rsbuild'}
  getRsbuildPlugin->>toRsbuildPlugin: rawPlugin[]
  toRsbuildPlugin-->>PluginAuthor: RsbuildPlugin
  PluginAuthor->>RsbuildAPI: register via rsbuild.config
  RsbuildAPI->>toRsbuildPlugin: setup(api)
  toRsbuildPlugin->>toRsbuildPlugin: meta.versions.rsbuild = api.context.version
  toRsbuildPlugin->>getRspackPluginFromRaw: rawPlugin[]
  getRspackPluginFromRaw->>RsbuildAPI: RspackPlugin
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐇 Hop, hop, a new tool joins the crew,
Rsbuild adapter, shiny and new!
createRsbuildPlugin leaps into place,
Rspack hooks shared with elegant grace.
The warren grows — more bundlers, more cheer,
Another entrypoint for all engineers! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add rsbuild adapter' clearly summarizes the main change - adding first-class Rsbuild support to unplugin.
Linked Issues check ✅ Passed The PR fully implements issue #607 requirements: provides createRsbuildPlugin factory, exposes .rsbuild getter on createUnplugin, enables my-plugin/rsbuild entrypoints, and achieves feature parity with other adapters.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the Rsbuild adapter feature: implementation in src/rsbuild/, type updates, documentation, tests, and supporting infrastructure for Rsbuild builds.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add first-class Rsbuild adapter

1 participant