Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support nested plugins #176

Merged
merged 14 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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