Skip to content

Commit 791fb7b

Browse files
yslpnsxzz
andauthored
feat: add rsbuild adapter (#608)
* feat: add rsbuild adapter * fix(rsbuild): ensure plugins array is initialized before modification * refactor(rspack): extract getRspackVersion function for version retrieval * refactor(rspack): remove applyRspackHook option and simplify plugin application --------- Co-authored-by: Kevin Deng <sxzz@sxzz.moe>
1 parent df47aa2 commit 791fb7b

27 files changed

Lines changed: 860 additions & 219 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Currently supports:
1313
- [Webpack](https://webpack.js.org/)
1414
- [esbuild](https://esbuild.github.io/)
1515
- [Rspack](https://www.rspack.dev/)
16+
- [Rsbuild](https://rsbuild.rs/)
1617
- [Rolldown](https://rolldown.rs/)
1718
- [Farm](https://www.farmfe.org/)
1819
- [Bun](https://bun.com/)

docs/.vitepress/assets/rsbuild.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/.vitepress/assets/rspack.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/.vitepress/theme/style.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ img[src*="features"] {
102102
width: 48px;
103103
}
104104

105-
img[src*="/features/rspack"] {
106-
margin-bottom: 28px!important;
107-
}
108-
109105
details > summary:hover {
110106
cursor: pointer;
111107
user-select: none;

docs/guide/index.md

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ lastUpdated: false
1616
- [webpack](https://webpack.js.org/)
1717
- [esbuild](https://esbuild.github.io/)
1818
- [Rspack](https://www.rspack.dev/)
19+
- [Rsbuild](https://rsbuild.rs/)
1920
- [Rolldown](https://rolldown.rs/)
2021
- [Farm](https://www.farmfe.org/)
2122
- [Bun](https://bun.com/)
@@ -131,6 +132,20 @@ module.exports = {
131132
}
132133
```
133134

135+
```ts [Rsbuild]
136+
// rsbuild.config.ts
137+
import { defineConfig } from '@rsbuild/core'
138+
import Starter from 'unplugin-starter/rsbuild'
139+
140+
export default defineConfig({
141+
plugins: [
142+
Starter({
143+
/* options */
144+
}),
145+
],
146+
})
147+
```
148+
134149
```js [esbuild]
135150
// esbuild.config.js
136151
import { build } from 'esbuild'
@@ -209,18 +224,18 @@ export default defineConfig({
209224

210225
## Supported Hooks
211226

212-
| Hook | Rollup | Vite | webpack | esbuild | Rspack | Farm | Rolldown | Bun |
213-
| --------------------------------------------------------------------------------- | :-------------: | :--: | :-----: | :-------------: | :-------------: | :--: | :------: | :-------------: |
214-
| [`enforce`](https://vite.dev/guide/api-plugin.html#plugin-ordering) | ❌ <sup>1</sup> ||| ❌ <sup>1</sup> |||||
215-
| [`buildStart`](https://rollupjs.org/plugin-development/#buildstart) |||||||||
216-
| [`resolveId`](https://rollupjs.org/plugin-development/#resolveid) ||||| ✅ <sup>5</sup> ||||
217-
| ~~`loadInclude`~~<sup>2</sup> |||||||||
218-
| [`load`](https://rollupjs.org/plugin-development/#load) |||| ✅ <sup>3</sup> |||||
219-
| ~~`transformInclude`~~<sup>2</sup> |||||||||
220-
| [`transform`](https://rollupjs.org/plugin-development/#transform) |||| ✅ <sup>3</sup> |||||
221-
| [`watchChange`](https://rollupjs.org/plugin-development/#watchchange) |||||||||
222-
| [`buildEnd`](https://rollupjs.org/plugin-development/#buildend) |||||||| ✅ <sup>6</sup> |
223-
| [`writeBundle`](https://rollupjs.org/plugin-development/#writebundle)<sup>4</sup> |||||||| ✅ <sup>6</sup> |
227+
| Hook | Rollup | Vite | webpack | esbuild | Rspack | Rsbuild | Farm | Rolldown | Bun |
228+
| --------------------------------------------------------------------------------- | :-------------: | :--: | :-----: | :-------------: | :-------------: | :-------------: | :--: | :------: | :-------------: |
229+
| [`enforce`](https://vite.dev/guide/api-plugin.html#plugin-ordering) | ❌ <sup>1</sup> ||| ❌ <sup>1</sup> || | |||
230+
| [`buildStart`](https://rollupjs.org/plugin-development/#buildstart) |||||| | |||
231+
| [`resolveId`](https://rollupjs.org/plugin-development/#resolveid) ||||| ✅ <sup>5</sup> | ✅ <sup>5</sup> | |||
232+
| ~~`loadInclude`~~<sup>2</sup> |||||| | |||
233+
| [`load`](https://rollupjs.org/plugin-development/#load) |||| ✅ <sup>3</sup> || | |||
234+
| ~~`transformInclude`~~<sup>2</sup> |||||| | |||
235+
| [`transform`](https://rollupjs.org/plugin-development/#transform) |||| ✅ <sup>3</sup> || | |||
236+
| [`watchChange`](https://rollupjs.org/plugin-development/#watchchange) |||||| | |||
237+
| [`buildEnd`](https://rollupjs.org/plugin-development/#buildend) |||||| | || ✅ <sup>6</sup> |
238+
| [`writeBundle`](https://rollupjs.org/plugin-development/#writebundle)<sup>4</sup> |||||| | || ✅ <sup>6</sup> |
224239

225240
::: details Notice
226241

@@ -230,7 +245,7 @@ export default defineConfig({
230245
In Rollup, this hook has been polyfilled to match the behaviors. See the following usage examples for reference.
231246
3. Although esbuild can handle both JavaScript and CSS and many other file formats, you can only return JavaScript in `load` and `transform` results.
232247
4. Currently, `writeBundle` is only serves as a hook for the timing. It doesn't pass any arguments.
233-
5. Rspack supports `resolveId` with a minimum required version of v1.0.0-alpha.1.
248+
5. Rspack and Rsbuild support `resolveId` with a minimum required Rspack version of v1.0.0-alpha.1.
234249
6. Bun supports `buildEnd` and `writeBundle` with a minimum required version of v1.3.0.
235250

236251
:::
@@ -268,6 +283,7 @@ export const rollupPlugin = unplugin.rollup
268283
export const rolldownPlugin = unplugin.rolldown
269284
export const webpackPlugin = unplugin.webpack
270285
export const rspackPlugin = unplugin.rspack
286+
export const rsbuildPlugin = unplugin.rsbuild
271287
export const esbuildPlugin = unplugin.esbuild
272288
export const farmPlugin = unplugin.farm
273289
export const bunPlugin = unplugin.bun
@@ -307,14 +323,14 @@ More details can be found in the [Rolldown's documentation](https://rolldown.rs/
307323

308324
## Supported Context
309325

310-
| Context | Rollup | Vite | webpack | esbuild | Rspack | Farm | Rolldown | Bun |
311-
| ------------------------------------------------------------------------------------- | :----: | :--: | :-----: | :-----: | :----: | :--: | :------: | :-: |
312-
| [`this.parse`](https://rollupjs.org/plugin-development/#this-parse)<sup>1</sup> |||||||||
313-
| [`this.addWatchFile`](https://rollupjs.org/plugin-development/#this-addwatchfile) |||||||||
314-
| [`this.emitFile`](https://rollupjs.org/plugin-development/#this-emitfile)<sup>2</sup> |||||||||
315-
| [`this.getWatchFiles`](https://rollupjs.org/plugin-development/#this-getwatchfiles) |||||||||
316-
| [`this.warn`](https://rollupjs.org/plugin-development/#this-warn) |||||||||
317-
| [`this.error`](https://rollupjs.org/plugin-development/#this-error) |||||||||
326+
| Context | Rollup | Vite | webpack | esbuild | Rspack | Rsbuild | Farm | Rolldown | Bun |
327+
| ------------------------------------------------------------------------------------- | :----: | :--: | :-----: | :-----: | :----: | :-----: | :--: | :------: | :-: |
328+
| [`this.parse`](https://rollupjs.org/plugin-development/#this-parse)<sup>1</sup> |||||| | |||
329+
| [`this.addWatchFile`](https://rollupjs.org/plugin-development/#this-addwatchfile) |||||| | |||
330+
| [`this.emitFile`](https://rollupjs.org/plugin-development/#this-emitfile)<sup>2</sup> |||||| | |||
331+
| [`this.getWatchFiles`](https://rollupjs.org/plugin-development/#this-getwatchfiles) |||||| | |||
332+
| [`this.warn`](https://rollupjs.org/plugin-development/#this-warn) |||||| | |||
333+
| [`this.error`](https://rollupjs.org/plugin-development/#this-error) |||||| | |||
318334

319335
::: info Notice
320336

@@ -329,9 +345,9 @@ More details can be found in the [Rolldown's documentation](https://rolldown.rs/
329345

330346
### Bundler Supported
331347

332-
| Rollup | Vite | webpack | Rspack | esbuild | Farm | Rolldown | Bun |
333-
| :--------------------: | :--: | :-----: | :----: | :-----: | :--: | :------: | :-: |
334-
|`>=3.1`<sup>1</sup> ||||||||
348+
| Rollup | Vite | webpack | Rspack | Rsbuild | esbuild | Farm | Rolldown | Bun |
349+
| :--------------------: | :--: | :-----: | :----: | :-----: | :-----: | :--: | :------: | :-: |
350+
|`>=3.1`<sup>1</sup> ||||| | |||
335351

336352
::: details Notice
337353

@@ -386,7 +402,7 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
386402
options,
387403
meta,
388404
) => {
389-
console.log(meta.framework) // vite | rollup | webpack | esbuild | rspack | farm | bun
405+
console.log(meta.framework) // vite | rollup | webpack | esbuild | rspack | rsbuild | farm | bun
390406

391407
return {
392408
name: 'unplugin-starter',
@@ -417,6 +433,12 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
417433
rspack(compiler) {
418434
// Configure Rspack compiler
419435
},
436+
rsbuild: {
437+
// Rsbuild plugin
438+
setup(api) {
439+
// Configure Rsbuild
440+
},
441+
},
420442
esbuild: {
421443
// Change the filter of onResolve and onLoad
422444
// onResolveFilter?: RegExp,
@@ -464,19 +486,26 @@ export const unpluginFactory = defineUnplugin((options, meta) => {
464486
const bundlerVersion = meta.versions.rollup ?? meta.versions.rolldown
465487
console.log(`Vite is using bundler version: ${bundlerVersion}`)
466488
}
489+
490+
// For Rsbuild, you can also access the underlying Rspack version
491+
if (meta.framework === 'rsbuild') {
492+
const rspackVersion = meta.versions.rspack
493+
console.log(`Rsbuild is using Rspack version: ${rspackVersion}`)
494+
}
467495
}
468496
}
469497
})
470498
```
471499

472-
| Rollup | Vite | webpack | Rspack | esbuild | Farm | Rolldown | Unloader | Bun |
473-
| :------------: | :--------------: | :-----: | :----: | :-----: | :--: | :------------: | :------------: | :-: |
474-
| ✅<sup>1</sup> | ✅<sup>1,2</sup> ||||| ✅<sup>1</sup> | ✅<sup>1</sup> ||
500+
| Rollup | Vite | webpack | Rspack | Rsbuild | esbuild | Farm | Rolldown | Unloader | Bun |
501+
| :------------: | :--------------: | :-----: | :----: | :------------: | :-----: | :--: | :------------: | :------------: | :-: |
502+
| ✅<sup>1</sup> | ✅<sup>1,2</sup> ||| ✅<sup>3</sup> | || ✅<sup>1</sup> | ✅<sup>1</sup> ||
475503

476504
::: details Notice
477505

478506
1. For Rollup-compatible hosts (`vite`, `rollup`, `rolldown`, `unloader`), framework versions are only available after the `buildStart` hook. The `unplugin` version is always available.
479507
2. Vite requires **v7.0.0 or later** to provide `viteVersion` ([vitejs/vite#20088](https://github.com/vitejs/vite/pull/20088)). On earlier versions, `meta.versions.vite` will be `undefined`. Vite also provides the underlying bundler version (`rollup` or `rolldown`).
508+
3. Rsbuild also provides the underlying Rspack version via `meta.versions.rspack`.
480509

481510
:::
482511

@@ -492,6 +521,7 @@ import {
492521
createFarmPlugin,
493522
createRolldownPlugin,
494523
createRollupPlugin,
524+
createRsbuildPlugin,
495525
createRspackPlugin,
496526
createVitePlugin,
497527
createWebpackPlugin,
@@ -503,6 +533,7 @@ const rolldownPlugin = createRolldownPlugin(/* factory */)
503533
const esbuildPlugin = createEsbuildPlugin(/* factory */)
504534
const webpackPlugin = createWebpackPlugin(/* factory */)
505535
const rspackPlugin = createRspackPlugin(/* factory */)
536+
const rsbuildPlugin = createRsbuildPlugin(/* factory */)
506537
const farmPlugin = createFarmPlugin(/* factory */)
507538
const bunPlugin = createBunPlugin(/* factory */)
508539
```

docs/index.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar: false
55
hero:
66
name: Unplugin
77
text: The Unified<br>Plugin System
8-
tagline: Supports Vite, Rollup, webpack, esbuild, Bun, and every framework built on top of them.
8+
tagline: Supports Vite, Rollup, webpack, Rspack, Rsbuild, esbuild, Bun, and every framework built on top of them.
99
image:
1010
light: /logo_light.svg
1111
dark: /logo_dark.svg
@@ -50,7 +50,13 @@ features:
5050
details: A fast Rust-based web bundler.
5151
link: https://www.rspack.dev/
5252
icon:
53-
src: /features/rspack.png
53+
src: /features/rspack.svg
54+
55+
- title: Rsbuild
56+
details: A Rspack-based build tool.
57+
link: https://rsbuild.rs/
58+
icon:
59+
src: /features/rsbuild.svg
5460

5561
- title: Farm
5662
details: Extremely fast web build tool written in Rust

docs/public/features/rsbuild.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/public/features/rspack.png

-7.64 KB
Binary file not shown.

docs/public/features/rspack.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
customIcon: {
2121
farm: localIconLoader(import.meta.url, '.vitepress/assets/farm.svg'),
2222
rolldown: localIconLoader(import.meta.url, '.vitepress/assets/rolldown.svg'),
23+
rsbuild: localIconLoader(import.meta.url, '.vitepress/assets/rsbuild.svg'),
2324
rspack: localIconLoader(import.meta.url, '.vitepress/assets/rspack.svg'),
2425
},
2526
}),

0 commit comments

Comments
 (0)