# @dtwo/unplugin

> Unified plugin system for build tools

Latest version **1.0.1** (published 2026-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dtwo/unplugin
pnpm add @dtwo/unplugin
yarn add @dtwo/unplugin
bun add @dtwo/unplugin
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2026-01-14 |
| First published | 2023-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 111.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nkduy |

## Links

- npm: https://www.npmjs.com/package/@dtwo/unplugin
- Repository: https://github.com/d2js/unplugin
- Homepage: https://github.com/d2js/unplugin#readme
- Issues: https://github.com/d2js/unplugin/issues
- npm.io page: https://npm.io/package/@dtwo/unplugin

## Dependencies (4)

- [acorn](https://npm.io/package/acorn.md) 8.8.1
- [chokidar](https://npm.io/package/chokidar.md) 3.5.3
- [webpack-sources](https://npm.io/package/webpack-sources.md) 3.2.3
- [webpack-virtual-modules](https://npm.io/package/webpack-virtual-modules.md) 0.5.0

## Recent versions

- 1.0.1 (latest) — 2026-01-14
- 1.0.0 — 2023-11-19

## README

# @dtwo/unplugin

Unified plugin system for build tools.

Currently supports:
- [Wite](https://witejs.web.app/)
- [Rollup](https://rollupjs.org/)
- [Webpack](https://webpack.js.org/)
- [esbuild](https://esbuild.github.io/)

###### 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

###### Wite

```ts
// wite.config.ts
import UnpluginFeature from './unplugin-feature'

export default {
  plugins: [
    UnpluginFeature.wite({ /* options */ })
  ]
}
```

###### Rollup

```ts
// rollup.config.js
import UnpluginFeature from './unplugin-feature'

export default {
  plugins: [
    UnpluginFeature.rollup({ /* options */ })
  ]
}
```

###### Webpack

```ts
// webpack.config.js
module.exports = {
  plugins: [
    require('./unplugin-feature').webpack({ /* options */ })
  ]
}
```

###### esbuild

```ts
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [
    require('./unplugin-feature').esbuild({ /* options */ })
  ]
})
```

### Framework-specific Logic

While `unplugin` provides compatible layers for some hooks, the functionality of it is limited to the common subset of the build's plugins capability. For more advanced framework-specific usages, `unplugin` provides an escape hatch for that.

```ts
export const unplugin = createUnplugin((options: UserOptions, meta) => {

  console.log(meta.framework) // 'wite' | 'rollup' | 'webpack' | 'esbuild'

  return {
    // common unplugin hooks
    name: 'unplugin-prefixed-name',
    transformInclude (id) { /* ... */ },
    transform (code) { /* ... */  },

    // framework specific hooks
    wite: {
      // Wite plugin
      configureServer(server) {
        // configure Wite server
      },
      // ...
    },
    rollup: {
      // Rollup plugin
    },
    webpack(compiler) {
      // configure Webpack compiler
    },
    esbuild: {
      // change the filter of onResolve and onLoad
      onResolveFilter?: RegExp
      onLoadFilter?: RegExp
      // or you can completely replace the setup logic
      setup?: EsbuildPlugin['setup']
    }
  }
})
```

## License

[MIT](./LICENSE) License

---
_Source: https://npm.io/package/@dtwo/unplugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
