npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wyatex/unplugin

v1.3.2

Published

Unified plugin system for build tools

Readme

unplugin

npm version npm downloads License

Unified plugin system for build tools.

Currently supports:

Hooks

unplugin extends the excellent Rollup plugin API 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 | Rspack | | ----------------------------------------------------------------------- | :-------------: | :--: | :-------: | :-------: | :-------------: | :----: | | enforce | ❌ 1 | ✅ | ✅ | ✅ | ❌ 1 | ✅ | | buildStart | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | resolveId | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | | loadInclude2 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | load | ✅ | ✅ | ✅ | ✅ | ✅ 3 | ✅ | | transformInclude2 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | transform | ✅ | ✅ | ✅ | ✅ | ✅ 3 | ✅ | | watchChange | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | | buildEnd | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | writeBundle4 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

  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.

Warning: The Rspack support is experimental. Future changes to Rspack integrations might not follow semver, please pin unplugin in your dependency when using. It's not recommended to use in production.

Hook Context

Supported

| Hook | Rollup | Vite | Webpack 4 | Webpack 5 | esbuild | Rspack | | -------------------------------------------------------------------------- | :----: | :--: | :-------: | :-------: | :-----: | :----: | | this.parse | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | this.addWatchFile | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | | this.emitFile5 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | this.getWatchFiles | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | | this.warn | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | this.error | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

  1. Currently, this.emitFile only supports the EmittedAsset variant.

Usage

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(/<template>/, '<template><div>Injected</div>')
    },
    // more hooks coming
  }
})

export const vitePlugin = unplugin.vite
export const rollupPlugin = unplugin.rollup
export const webpackPlugin = unplugin.webpack
export const rspackPlugin = unplugin.rspack
export const esbuildPlugin = unplugin.esbuild

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 | Rspack | esbuild | | :--------------------: | :--: | :-------: | :-------: | :----: | :------------: | | ✅ >=3.16 | ✅ | ✅ | ✅ | ✅ | ⚠️7 |

  1. Rollup supports nested plugins since v3.1.0. Plugin aurthor should ask users to a have a Rollup version of >=3.1.0 when using nested plugins. For singe plugin format, unplugin works for any versions of Rollup.
  2. 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
import { createUnplugin } from 'unplugin'

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

Plugin Installation

Vite
// vite.config.ts
import UnpluginFeature from './unplugin-feature'

export default {
  plugins: [
    UnpluginFeature.vite({ /* options */ }),
  ],
}
Rollup
// rollup.config.js
import UnpluginFeature from './unplugin-feature'

export default {
  plugins: [
    UnpluginFeature.rollup({ /* options */ }),
  ],
}
Webpack
// webpack.config.js
module.exports = {
  plugins: [
    require('./unplugin-feature').webpack({ /* options */ }),
  ],
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [
    require('./unplugin-feature').esbuild({ /* options */ }),
  ],
})
Rspack
// rspack.config.js
module.exports = {
  plugins: [
    require('./unplugin-feature').rspack({ /* 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.

export const unplugin = createUnplugin((options: UserOptions, meta) => {
  console.log(meta.framework) // 'vite' | 'rollup' | 'webpack' | 'rspack' | 'esbuild'

  return {
    // common unplugin hooks
    name: 'unplugin-prefixed-name',
    transformInclude(id) { /* ... */ },
    transform(code) { /* ... */ },

    // framework specific hooks
    vite: {
      // Vite plugin
      configureServer(server) {
        // configure Vite server
      },
      // ...
    },
    rollup: {
      // Rollup plugin
    },
    webpack(compiler) {
      // configure Webpack compiler
    },
    rspack(compiler) {
      // configure Rspack compiler
    },
    esbuild: {
      // change the filter of onResolve and onLoad
      onResolveFilter?: RegExp,
      onLoadFilter?: RegExp,
      // or you can completely replace the setup logic
      setup?: EsbuildPlugin.setup,
    },
  }
})

Creating platform specific plugins

The package exports a set of functions in place of createUnplugin that allow for the creation of plugins for specific bundlers. Each of the function takes the same generic factory argument as createUnplugin.

import {
  creteEsbuildPlugin,
  getRollupPlugin,
  getRspackPlugin,
  getVitePlugin,
  getWebpackPlugin
} from 'unplugin'

const vitePlugin = getVitePlugin({ /* options */ })
const rollupPlugin = getRollupPlugin({ /* options */ })
const esbuildPlugin = creteEsbuildPlugin({ /* options */ })
const webpackPlugin = getWebpackPlugin({ /* options */ })
const rspackPlugin = getRspackPlugin({ /* options */ })

Conventions

  • Plugins powered by unplugin should have a clear name with unplugin- prefix.

  • Include unplugin keyword in package.json.

  • To provide better DX, packages could export 2 kinds of entry points:

    • Default export: the returned value of createUnplugin function

      import UnpluginFeature from 'unplugin-feature'
    • Subpath exports: properties of the returned value of createUnplugin function for each framework users

      import VitePlugin from 'unplugin-feature/vite'
    • Refer to unplugin-starter for more details about this setup.

Starter Templates

Community Showcases

License

MIT License © 2021-PRESENT Nuxt Contrib