Skip to content

Commit

Permalink
feat: support farm plugin (#341)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
ErKeLost and antfu authored Mar 13, 2024
1 parent 2a1dbef commit 731a596
Show file tree
Hide file tree
Showing 20 changed files with 1,329 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Currently supports:
- [esbuild](https://esbuild.github.io/)
- [Rspack](https://www.rspack.dev/) (⚠️ experimental)
- [Rolldown](https://rolldown.rs/) (⚠️ experimental)
- [Farm](https://farm-fe.github.io/)
- And every framework built on top of them.

## Documentations
Expand Down
68 changes: 44 additions & 24 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lastUpdated: false
- [esbuild](https://esbuild.github.io/)
- [Rspack](https://www.rspack.dev/) <span style="color: #ca8a04"><strong>(⚠️ experimental)</strong></span>
- [Rolldown](https://rolldown.rs/) <span style="color: #ca8a04"><strong>(⚠️ experimental)</strong></span>
- [Farm](https://farm-fe.github.io/)

## Trying It Online

Expand Down Expand Up @@ -119,6 +120,19 @@ build({
})
```

```ts [Farm]
// farm.config.ts
import Starter from 'unplugin-starter/farm'

export default defineConfig({
plugins: [
Starter({
/* options */
}),
],
})
```

```js [Vue-CLI]
// vue.config.js
module.exports = {
Expand Down Expand Up @@ -154,18 +168,18 @@ export default defineConfig({

## Supported Hooks

| Hook | Rollup | Vite | webpack 4 | webpack 5 | esbuild | Rspack |
| ----------------------------------------------------------------------------------| :-------------: | :--: | :-------: | :-------: | :-----------: | :----: |
| [`enforce`](https://vitejs.dev/guide/api-plugin.html#plugin-ordering) | ❌ <sup>1</sup> |||| ❌ <sup>1</sup> ||
| [`buildStart`](https://rollupjs.org/plugin-development/#buildstart) |||||||
| [`resolveId`](https://rollupjs.org/plugin-development/#resolveid) |||||||
| `loadInclude`<sup>2</sup> |||||||
| [`load`](https://rollupjs.org/plugin-development/#load) ||||| ✅ <sup>3</sup> ||
| `transformInclude`<sup>2</sup> |||||||
| [`transform`](https://rollupjs.org/plugin-development/#transform) ||||| ✅ <sup>3</sup> ||
| [`watchChange`](https://rollupjs.org/plugin-development/#watchchange) |||||||
| [`buildEnd`](https://rollupjs.org/plugin-development/#buildend) |||||||
| [`writeBundle`](https://rollupjs.org/plugin-development/#writebundle)<sup>4</sup> |||||||
| Hook | Rollup | Vite | webpack 4 | webpack 5 | esbuild | Rspack | Farm |
| ----------------------------------------------------------------------------------| :-------------: | :--: | :-------: | :-------: | :-----------: | :----: | :---: |
| [`enforce`](https://vitejs.dev/guide/api-plugin.html#plugin-ordering) | ❌ <sup>1</sup> |||| ❌ <sup>1</sup> |||
| [`buildStart`](https://rollupjs.org/plugin-development/#buildstart) ||||||||
| [`resolveId`](https://rollupjs.org/plugin-development/#resolveid) ||||||||
| `loadInclude`<sup>2</sup> ||||||||
| [`load`](https://rollupjs.org/plugin-development/#load) ||||| ✅ <sup>3</sup> |||
| `transformInclude`<sup>2</sup> ||||||||
| [`transform`](https://rollupjs.org/plugin-development/#transform) ||||| ✅ <sup>3</sup> |||
| [`watchChange`](https://rollupjs.org/plugin-development/#watchchange) ||||||||
| [`buildEnd`](https://rollupjs.org/plugin-development/#buildend) ||||||||
| [`writeBundle`](https://rollupjs.org/plugin-development/#writebundle)<sup>4</sup> ||||||||

::: details Notice
1. Rollup and esbuild do not support using `enforce` to control the order of plugins. Users need to maintain the order manually.
Expand Down Expand Up @@ -207,18 +221,19 @@ export const rollupPlugin = unplugin.rollup
export const webpackPlugin = unplugin.webpack
export const rspackPlugin = unplugin.rspack
export const esbuildPlugin = unplugin.esbuild
export const farmPlugin = unplugin.farm
```

## Supported Context

| Context | Rollup | Vite | webpack 4 | webpack 5 | esbuild | Rspack |
| -------------------------------------------------------------------------- | :----: | :--: | :-------: | :-------: | :-----: | :----: |
| [`this.parse`](https://rollupjs.org/plugin-development/#this-parse) |||||||
| [`this.addWatchFile`](https://rollupjs.org/plugin-development/#this-addwatchfile) |||||||
| [`this.emitFile`](https://rollupjs.org/plugin-development/#this-emitfile)<sup>1</sup> |||||||
| [`this.getWatchFiles`](https://rollupjs.org/plugin-development/#this-getwatchfiles) |||||||
| [`this.warn`](https://rollupjs.org/plugin-development/#this-warn) |||||||
| [`this.error`](https://rollupjs.org/plugin-development/#this-error) |||||||
| Context | Rollup | Vite | webpack 4 | webpack 5 | esbuild | Rspack | Farm |
| -------------------------------------------------------------------------- | :----: | :--: | :-------: | :-------: | :-----: | :----: | :---: |
| [`this.parse`](https://rollupjs.org/plugin-development/#this-parse) ||||||||
| [`this.addWatchFile`](https://rollupjs.org/plugin-development/#this-addwatchfile) ||||||||
| [`this.emitFile`](https://rollupjs.org/plugin-development/#this-emitfile)<sup>1</sup> ||||||||
| [`this.getWatchFiles`](https://rollupjs.org/plugin-development/#this-getwatchfiles) ||||||||
| [`this.warn`](https://rollupjs.org/plugin-development/#this-warn) ||||||||
| [`this.error`](https://rollupjs.org/plugin-development/#this-error) ||||||||

::: info Notice
1. Currently, [`this.emitFile`](https://rollupjs.org/plugin-development/#thisemitfile) only supports the `EmittedAsset` variant.
Expand All @@ -230,9 +245,9 @@ Since `v0.10.0`, **Unplugin** supports constructing multiple nested plugins to b

### Bundler Supported

| Rollup | Vite | webpack 4 | webpack 5 | Rspack | esbuild |
| :--------------------: | :--: | :-------: | :-------: | :----: | :----------: |
|`>=3.1`<sup>1</sup> ||||| ✅ (v1.8.0+) |
| Rollup | Vite | webpack 4 | webpack 5 | Rspack | esbuild | Farm |
| :--------------------: | :--: | :-------: | :-------: | :----: | :----------: | :--: |
|`>=3.1`<sup>1</sup> ||||| ✅ (v1.8.0+) ||

::: details Notice
1. Rollup supports nested plugins since [v3.1.0](https://github.com/rollup/rollup/releases/tag/v3.1.0). Plugin author should ask users to have a Rollup version of `>=3.1.0` when using nested plugins. For single plugin format, **Unplugin** works for any version of Rollup.
Expand Down Expand Up @@ -319,6 +334,9 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (options, m
// Or you can completely replace the setup logic
// setup?: EsbuildPlugin.setup,
},
farm: {
// Farm plugin
}
}
}

Expand All @@ -335,15 +353,17 @@ Each of the function takes the same generic factory argument as `createUnplugin`
```ts
import {
createEsbuildPlugin,
createFarmPlugin,
createRollupPlugin,
createRspackPlugin,
createVitePlugin,
createWebpackPlugin
createWebpackPlugin,
} from 'unplugin'

const vitePlugin = createVitePlugin({ /* options */ })
const rollupPlugin = createRollupPlugin({ /* options */ })
const esbuildPlugin = createEsbuildPlugin({ /* options */ })
const webpackPlugin = createWebpackPlugin({ /* options */ })
const rspackPlugin = createRspackPlugin({ /* options */ })
const farmPlugin = createFarmPlugin({ /* options */ })
```
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ features:
icon:
src: /features/rspack.png

- title: Farm
details: Extremely fast web build tool written in Rust
link: https://farm-fe.github.io/
icon:
src: /features/farm.png

- title: Rolldown
details: Fast Rust bundler for JavaScript with Rollup-compatible API
link: https://rolldown.rs/
icon:
src: /features/rolldown.svg

- title: More
details: More supported bundlers...
link: /guide/#supported-hooks
Expand Down
Binary file added docs/public/features/farm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions docs/public/features/rolldown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"@ampproject/remapping": "^2.3.0",
"@antfu/eslint-config": "^2.8.0",
"@antfu/ni": "^0.21.12",
"@farmfe/cli": "^0.7.0",
"@farmfe/core": "^1.0.0-beta.0",
"@rolldown/node": "^0.0.5",
"@rspack/cli": "^0.5.6",
"@rspack/core": "^0.5.6",
Expand Down
Loading

0 comments on commit 731a596

Please sign in to comment.