{"id":20064,"library":"git-revision-webpack-plugin","title":"GitRevisionWebpackPlugin","description":"A webpack plugin (v5.0.0, latest stable) that generates VERSION, COMMITHASH, and optionally BRANCH files during build by executing local git commands. Supports path substitutions (e.g., [git-revision-version]) in webpack output filenames and exposes a public API for use with DefinePlugin. Differentiators: lightweight, TypeScript types included, supports lightweight tags and custom git commands, minimal configuration. Active development, with breaking changes in v5 requiring named exports.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/pirelenito/git-revision-webpack-plugin","tags":["javascript","typescript"],"install":[{"cmd":"npm install git-revision-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add git-revision-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add git-revision-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import; in CommonJS use `const { GitRevisionPlugin } = require(...)`. Default export removed in v5.","wrong":"const GitRevisionPlugin = require('git-revision-webpack-plugin')","symbol":"GitRevisionPlugin","correct":"import { GitRevisionPlugin } from 'git-revision-webpack-plugin'"},{"note":"CJS require must use destructuring. Using .default will yield undefined.","wrong":"const GitRevisionPlugin = require('git-revision-webpack-plugin').default","symbol":"GitRevisionPlugin (CJS)","correct":"const { GitRevisionPlugin } = require('git-revision-webpack-plugin')"},{"note":"Instantiate after import. For CJS: `const { GitRevisionPlugin } = require(...)`, then `new GitRevisionPlugin(...)`.","wrong":"const plugin = new GitRevisionPlugin.default({ branch: true })","symbol":"GitRevisionPlugin with options","correct":"import { GitRevisionPlugin } from 'git-revision-webpack-plugin'\nconst plugin = new GitRevisionPlugin({ branch: true })"}],"quickstart":{"code":"// webpack.config.js\nimport { GitRevisionPlugin } from 'git-revision-webpack-plugin';\n\nexport default {\n  plugins: [\n    new GitRevisionPlugin({\n      branch: true,\n      lightweightTags: false,\n    }),\n  ],\n  output: {\n    filename: '[name]-[git-revision-hash].js',\n    publicPath: 'http://cdn.example.com/[git-revision-version]/',\n  },\n};","lang":"typescript","description":"Basic webpack config using GitRevisionPlugin to generate version files and use path substitutions for cache-busting filenames."},"warnings":[{"fix":"Use `const { GitRevisionPlugin } = require('git-revision-webpack-plugin')` or `import { GitRevisionPlugin } from 'git-revision-webpack-plugin'`.","message":"v5 changed exports: named export GitRevisionPlugin instead of default export. CJS require must use destructuring.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Upgrade to v4+ for LASTCOMMITDATETIME support.","message":"v3.0.6 reverted LASTCOMMITDATETIME from patch — it was accidentally included and removed; will be available in v4.","severity":"deprecated","affected_versions":"3.0.6"},{"fix":"Hardcode commands; never interpolate user input.","message":"Configuration commands are not sanitized. Avoid passing user input to `commithashCommand` or `versionCommand` to prevent command injection.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add `new GitRevisionPlugin({ lightweightTags: true })`.","message":"Lightweight tags are disabled by default. If your git tags are lightweight, set `lightweightTags: true` to get version output.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check peer deps: requires webpack ^5.0.0 from v5.0.0.","message":"v4.0.0 added Webpack 5 support and migrated to TypeScript (types included). Dropped support for Webpack 4?","severity":"breaking","affected_versions":">=4.0.0 <5.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import { GitRevisionPlugin }` or `const { GitRevisionPlugin } = require(...)`.","cause":"Using default import or wrong require pattern in v5.","error":"TypeError: GitRevisionPlugin is not a constructor"},{"fix":"Upgrade to v4.0.1 or v5; use destructured import.","cause":"v4 had default export issues, fixed in v4.0.1.","error":"Unable to load 4.0 using require"},{"fix":"Run `npm install --save-dev git-revision-webpack-plugin` and ensure config is correct.","cause":"Plugin not installed or misconfigured in webpack config.","error":"Module not found: Error: Can't resolve 'git-revision-webpack-plugin'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}