Skip to content

Commit

Permalink
feat: support nested plugins (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
  • Loading branch information
sxzz and antfu authored Oct 18, 2022
1 parent 55d7170 commit d35e055
Show file tree
Hide file tree
Showing 17 changed files with 524 additions and 400 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,42 @@ export const webpackPlugin = unplugin.webpack
export const esbuildPlugin = unplugin.esbuild
```

### Plugin Installation
## Nested Plugins

Since `v0.10.0`, unplugin supports constructing multiple nested plugins to behave like a single one. For example:

###### Supported

| Rollup | Vite | Webpack 4 | Webpack 5 | esbuild |
| :----: | :--: | :-------: | :-------: | :-----: |
|`>=3.1` |||| ⚠️<sup>5</sup> |

5. Since esbuild does not have a built-in transform phase, the `transform` hook of nested plugin will not work on esbuild yet. Other hooks like `load` or `resolveId` work fine. We will try to find a way to support it in the future.

###### Usage

```ts
import { createUnplugin } from 'unplugin'

export const unplugin = createUnplugin((options: UserOptions) => {
return [
{
name: 'plugin-a',
transform (code) {
// ...
}
},
{
name: 'plugin-b',
resolveId (id) {
// ...
}
}
]
})
```

## Plugin Installation

###### Vite

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@types/express": "^4.17.14",
"@types/fs-extra": "^9.0.13",
"@types/node": "^18.7.16",
"@types/node": "^18.11.0",
"@types/webpack-sources": "^3.2.0",
"bumpp": "^8.2.1",
"conventional-changelog-cli": "^2.2.2",
Expand All @@ -53,7 +53,7 @@
"jiti": "^1.16.0",
"magic-string": "^0.26.7",
"picocolors": "^1.0.0",
"rollup": "^2.79.1",
"rollup": "^3.2.2",
"tsup": "^6.3.0",
"typescript": "^4.8.4",
"vite": "^3.1.8",
Expand Down
36 changes: 22 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/buildFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function run () {
execSync('npx vite build', { cwd: path, stdio: 'inherit' })
console.log(c.red(c.inverse(c.bold('\n Rollup '))), name, '\n')
execSync('npx rollup --version', { cwd: path, stdio: 'inherit' })
execSync('npx rollup -c', { cwd: path, stdio: 'inherit' })
execSync('npx rollup --bundleConfigAsCjs -c', { cwd: path, stdio: 'inherit' })
console.log(c.blue(c.inverse(c.bold('\n Webpack '))), name, '\n')
execSync('npx webpack --version', { cwd: path, stdio: 'inherit' })
execSync('npx webpack', { cwd: path, stdio: 'inherit' })
Expand Down
Loading

0 comments on commit d35e055

Please sign in to comment.