rollup-plugin-build-git-version

raw JSON →
0.0.9 verified Mon Apr 27 auth: no javascript maintenance

A Rollup plugin that generates a version.json file containing git information (branch, commit id, time, message, author) and build time during the bundle process. Current version 0.0.9 is stable but likely early-stage; release cadence is unknown. Key differentiator: provides structured git metadata directly in the output, useful for CI/CD pipelines and runtime version display. Supports Node >=16 and pnpm 8.x. Ships TypeScript types. Note that the plugin uses require() in its own example, but Rollup encourages ESM imports.

error Error: Cannot find module 'rollup-plugin-build-git-version'
cause Package not installed or missing devDependency.
fix
npm install --save-dev rollup-plugin-build-git-version
error TypeError: buildGitVersion is not a function
cause Using default import instead of named import.
fix
Use import { buildGitVersion } from 'rollup-plugin-build-git-version'.
error SyntaxError: Unexpected token 'export'
cause Using require() with an ESM-only package.
fix
Switch to import syntax or use dynamic import().
gotcha The plugin example uses CommonJS require() but the package is ESM-only (has type: 'module' or uses ESM syntax).
fix Use import { buildGitVersion } from 'rollup-plugin-build-git-version'.
gotcha The generated version.json always overwrites the output; there is no option to merge with existing file.
fix Consider using before/after hooks or custom plugin to merge if needed.
breaking Plugin requires Node >=16 and pnpm >=8. Using older versions may fail due to unsupported APIs.
fix Update Node to >=16, or use an alternative if stuck on older Node.
gotcha The version.json is created at the root of the output directory; cannot change path without workaround.
fix Use Rollup's manual output or another plugin to move the file post-build.
npm install rollup-plugin-build-git-version
yarn add rollup-plugin-build-git-version
pnpm add rollup-plugin-build-git-version

This example shows how to integrate the plugin into a Rollup configuration, generating version.json in the output directory.

import { buildGitVersion } from 'rollup-plugin-build-git-version';
import { defineConfig } from 'rollup';

export default defineConfig({
  input: 'src/index.js',
  output: { dir: 'dist', format: 'cjs' },
  plugins: [buildGitVersion()]
});