Registry / devops / unplugin-info

unplugin-info

JSON →
library1.3.2jsnpmunverified

Unplugin Info is a versatile build-time plugin that exports essential build-related information as a virtual module, making it accessible within your application's runtime code. It captures details such as build timestamps, Git commit SHA, CI environment variables, and `package.json` data. This allows developers to easily inspect the production version of their application, verify deployments, or configure behavior based on build context. The current stable version is 1.3.2, with frequent patch and minor releases addressing bug fixes and adding support for new features or bundlers. Its key differentiator is its 'unplugin' architecture, providing seamless integration across various build tools like Vite, Rollup, Webpack, Rspack, esbuild, and specific frameworks like Nuxt, Astro, Quasar, and Vue CLI, all from a single codebase. It also provides dedicated TypeScript typings for virtual modules.

npm install unplugin-info
INSTALL
IMPORT
SIG · UNPLUGIN-INFO
U
unplugin-info
devopsjavascriptv1.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Vite Plugin
import Info from 'unplugin-info/vite';
import { Info } from 'unplugin-info/vite'; // Incorrect named import const Info = require('unplugin-info/vite'); // CommonJS import in ESM context
The Vite integration exports a default function. Ensure you're in an ESM context for `import` statements.
Webpack Plugin
require('unplugin-info/webpack')();
import Info from 'unplugin-info/webpack'; // Webpack config typically uses CommonJS for plugin instantiation Info(); // Missing call to the default function
Webpack configurations often use CommonJS `require`. The module exports a function that needs to be called to instantiate the plugin.
Nuxt Module
modules: ['unplugin-info/nuxt']
import Info from 'unplugin-info/nuxt'; // Not how Nuxt modules are typically registered modules: [Info]
Nuxt modules are typically registered as a string path in the `modules` array. Options are passed via the top-level `info` key in `nuxt.config.ts`.
TypeScript Types
/// <reference types="unplugin-info/client" /> // or in tsconfig.json "types": ["unplugin-info/client"]
import { BuildInfo } from 'unplugin-info/client'; // Incorrect import of ambient types
To get type inference for the virtual modules (e.g., `~build/info`), you need to reference the client types either via a triple-slash directive in a `.d.ts` file or by adding `unplugin-info/client` to the `types` array in your `tsconfig.json`.

This quickstart demonstrates configuring `unplugin-info` with Vite and then accessing the generated build, Git, CI, and package information within a client-side TypeScript file. It shows how to include custom data and environment variables.

import { defineConfig } from 'vite'; import Info from 'unplugin-info/vite'; // vite.config.ts export default defineConfig({ plugins: [ Info({ /** * Customize what information to include * * @default true */ git: true, // Includes Git commit SHA, branch, etc. buildTime: true, // Includes the build timestamp ci: true, // Includes CI environment variables packageJson: true, // Includes package.json version /** * Custom information to add to the virtual module */ custom: { myCustomKey: 'myCustomValue', envVar: process.env.MY_ENV_VAR ?? '' } }) ] }); // src/main.ts (or any client-side file) // Make sure to add "unplugin-info/client" to your tsconfig.json import buildInfo from '~build/info'; import buildGit from '~build/git'; import buildCI from '~build/ci'; import buildPackage from '~build/package'; console.log('Application Build Info:', buildInfo); console.log('Git Info:', buildGit); console.log('CI Info:', buildCI); console.log('Package Info:', buildPackage); document.getElementById('app')!.innerHTML = ` <h1>App Info</h1> <p>Build Time: ${new Date(buildInfo.time).toLocaleString()}</p> <p>Git Commit: ${buildGit.shortHash}</p> <p>CI: ${buildCI.name || 'Local'}</p> <p>Version: ${buildPackage.version}</p> <p>Custom: ${buildInfo.custom.myCustomKey} - ${buildInfo.custom.envVar}</p> `;
Debug
Known issues
breakingThe package underwent a significant breaking change in version 1.0 (migrated from v0), re-organizing the virtual modules. Git and CI-related information were moved from the single `~build/info` module to dedicated `~build/git` and `~build/ci` modules, respectively. Additionally, `commitsSinceLastTag` was removed from `~build/git`.
fix
Update import paths from `~build/info` to `~build/git` and `~build/ci` for corresponding data. Refactor code that relied on `commitsSinceLastTag`.
affects: >=1.0.0
gotchaWhen using `unplugin-info` with TypeScript, you must explicitly declare the virtual modules to the TypeScript compiler, otherwise, imports like `import buildInfo from '~build/info'` will result in type errors (e.g., 'Cannot find module '~build/info' or its corresponding type declarations.').
fix
Add `"unplugin-info/client"` to the `types` array in your `tsconfig.json`'s `compilerOptions`, or add a triple-slash directive `/// <reference types="unplugin-info/client" />` in a `.d.ts` file within your project.
affects: >=1.0.0
gotchaThe plugin relies on Git commands to fetch repository information. If Git is not installed or the project is not a Git repository (e.g., in a deployed environment or CI without Git clone), Git-related fields (`~build/git`) might be empty or throw errors during the build process, depending on the environment.
fix
Ensure Git is installed and the project is a Git repository during the build. For environments where Git info is not available or desired, you can disable `git: false` in the plugin options or add fallbacks in your application code.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module '~build/info' or its corresponding type declarations.
TypeScript compiler is unaware of the virtual module types.
fix
Add `"unplugin-info/client"` to the `types` array in `tsconfig.json` or add `/// <reference types="unplugin-info/client" />` to a `.d.ts` file.
ReferenceError: BuildInfo is not defined (or similar for other virtual modules)
Attempting to use `BuildInfo` (or `BuildGit`, etc.) as a global variable instead of importing the virtual module.
fix
Correctly import the virtual module using `import buildInfo from '~build/info';` (or `~build/git`, etc.) as an ESM import.
Rollup failed to resolve import "unplugin-info/vite" from "vite.config.ts".
Incorrect import path for the specific bundler plugin.
fix
Verify the correct import path for your bundler, e.g., `import Info from 'unplugin-info/vite';` for Vite, `require('unplugin-info/webpack')` for Webpack, etc. Ensure the package is installed.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies
@nuxt/kitoptionalRequired for Nuxt module integration.
@nuxt/schemaoptionalRequired for Nuxt module integration and type inference.
@rspack/coreoptionalRequired when using with Rspack.
esbuildoptionalRequired when using with esbuild.
rollupoptionalRequired when using with Rollup (or bundlers like Vite that use Rollup internally).
viteoptionalRequired when using with Vite.
webpackoptionalRequired when using with Webpack or compatible tools like Vue CLI/Quasar (webpack mode).
Agent activity
10 hits · last 30 days
node
8
Bingbot
1
OpenAI (training)
1
Resources
unplugin-info — npm install unplugin-info · libregistry