Unplugin: Unified Plugin System for Build Tools

repository·main·Indexed Apr 15, 2026

https://github.com/unjs/unplugin

Unplugin is a unified plugin system enabling developers to write plugins once and run them across various build tools and runtimes, including Vite, Rollup, webpack, esbuild, Rspack, Farm, Rolldown, and Bun. It abstracts differences between bundlers by providing a consistent API for hooks like resolveId, load, and transform. The library supports creating custom plugins via the createUnplugin factory, handling source maps, emitting files, and managing virtual modules. Official templates and conventions are available for plugin development.

Tokens
19K
Snippets
52
Records
102
Agent score
86%

What's inside unplugin

  1. Access Build Tool Versions and Metadata

    main

    Use the meta object passed to your plugin factory to access runtime information about the host environment. This is useful for conditional logic based on the build tool or its version.

    • meta.framework: Returns the name of the framework (e.g., 'vite', 'webpack', 'rollup').
    • meta.versions: An object containing version strings for the framework and unplugin itself.
      • meta.versions[meta.framework]: The version of the host framework (e.g., '7.0.0').
      • meta.versions.unplugin: The version of the unplugin library.
      • meta.versions.rollup or meta.versions.rolldown: The underlying bundler version when running inside Vite.

    Note: For Rollup-compatible hosts (Vite, Rollup, Rolldown, Unloader), framework versions are only available after the buildStart hook is executed. Vite requires version 7.0.0 or later to provide meta.versions.vite.

    Sources: unknown

  2. Install and Configure Unplugin

    main
    Unplugin is a unified plugin system that allows you to write plugins once and run them across various build tools and runtimes.
  3. Supported Build Tools

    main

    Unplugin currently supports:

    • Vite
    • Rollup
    • webpack
    • esbuild
    • Rspack
    • Rolldown
    • Farm
    • Bun

    Sources: docs/guide/index.md

  4. Installation

    main

    Install the unplugin package using your preferred package manager:

    npm install unplugin --save-dev
    yarn add unplugin -D
    pnpm add unplugin -D
    bun add unplugin -D
  5. Important Notes

    main
    1. Parser Implementation: For bundlers other than Rollup, Rolldown, or Vite, setParseImpl must be called to manually provide a parser implementation. Parsers such as Acorn, Babel, or Oxc can be used.

    2. emitFile Limitation: Currently, this.emitFile only supports the EmittedAsset variant.

    Sources: docs/guide/index.md