# unplugin [![NPM version](https://img.shields.io/npm/v/unplugin?color=a1b858&label=)](https://www.npmjs.com/package/unplugin) Unified plugin system for build tools. Currently supports: - [Vite](https://vitejs.dev/) - [Rollup](https://rollupjs.org/) - [Webpack](https://webpack.js.org/) - [esbuild](https://esbuild.github.io/) ## Hooks `unplugin` extends the excellent [Rollup plugin API](https://rollupjs.org/guide/en/#plugins-overview) as the unified plugin interface and provides a compatible layer base on the build tools used with. ###### Supported | Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild | | ---- | :----: | :--: | :-------: | :-------: | :-----: | | [`enforce`](https://rollupjs.org/guide/en/#enforce) | ❌ 1 | ✅ | ✅ | ✅ | ❌ 1 | | [`buildStart`](https://rollupjs.org/guide/en/#buildstart) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`resolveId`](https://rollupjs.org/guide/en/#resolveid) | ✅ | ✅ | ✅ | ✅ | ✅ | | `loadInclude`2 | ✅ | ✅ | ✅ | ✅ | ✅ | | [`load`](https://rollupjs.org/guide/en/#load) | ✅ | ✅ | ✅ | ✅ | ✅ 3 | | `transformInclude`2 | ✅ | ✅ | ✅ | ✅ | ✅ | | [`transform`](https://rollupjs.org/guide/en/#transformers) | ✅ | ✅ | ✅ | ✅ | ✅ 3 | | [`watchChange`](https://rollupjs.org/guide/en/#watchchange) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`buildEnd`](https://rollupjs.org/guide/en/#buildend) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`writeBundle`](https://rollupjs.org/guide/en/#writebundle)4 | ✅ | ✅ | ✅ | ✅ | ✅ | 1. Rollup and esbuild do not support using `enforce` to control the order of plugins. Users need to maintain the order manually. 2. Webpack's id filter is outside of loader logic; an additional hook is needed for better perf on Webpack. In Rollup and Vite, this hook has been polyfilled to match the behaviors. See for following usage examples. 3. Although esbuild can handle both JavaScript and CSS and many other file formats, you can only return JavaScript in `load` and `transform` results. 4. Currently, `writeBundle` is only serves as a hook for the timing. It doesn't pass any arguments. ### Hook Context ###### Supported | Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild | | ---- | :----: | :--: | :-------: | :-------: | :-----: | | [`this.parse`](https://rollupjs.org/guide/en/#thisparse) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`this.addWatchFile`](https://rollupjs.org/guide/en/#thisaddwatchfile) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`this.emitFile`](https://rollupjs.org/guide/en/#thisemitfile)5 | ✅ | ✅ | ✅ | ✅ | ✅ | | [`this.getWatchFiles`](https://rollupjs.org/guide/en/#thisgetwatchfiles) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`this.warn`](https://rollupjs.org/guide/en/#thiswarn) | ✅ | ✅ | ✅ | ✅ | ✅ | | [`this.error`](https://rollupjs.org/guide/en/#thiserror) | ✅ | ✅ | ✅ | ✅ | ✅ | 5. Currently, [`this.emitFile`](https://rollupjs.org/guide/en/#thisemitfile) only supports the `EmittedAsset` variant. ## Usage ```ts import { createUnplugin } from 'unplugin' export const unplugin = createUnplugin((options: UserOptions) => { return { name: 'unplugin-prefixed-name', // webpack's id filter is outside of loader logic, // an additional hook is needed for better perf on webpack transformInclude (id) { return id.endsWith('.vue') }, // just like rollup transform transform (code) { return code.replace(/