webpack-auto-inject-version
raw JSON → 1.2.2 verified Sat Apr 25 auth: no javascript maintenance
Webpack plugin that automatically injects version from package.json into bundle files as a comment block, replaces custom tags (e.g., [AIV]{version}[/AIV]) in HTML/CSS/JS, and optionally auto-increments the package version via webpack env flags (--env.major, --env.minor, --env.patch). Current stable version 1.2.2. Simple configuration with sensible defaults, all features enabled out of the box. Supports customization of comment format, date format, and tag regex. Limited maintenance; no major updates since 2019.
Common errors
error Module not found: Error: Can't resolve 'webpack-auto-inject-version' ↓
cause Missing npm install or incorrect import path.
fix
Run 'npm install webpack-auto-inject-version --save-dev' and use require('webpack-auto-inject-version').
Warnings
gotcha AutoIncreaseVersion in watch mode will increment version on every rebuild if runInWatchMode is true (default false). ↓
fix Set runInWatchMode to false (default) to avoid unintended version bumps during development.
deprecated Package has not been updated since 2019; may not work with latest webpack 5+ without adjustments. ↓
fix Consider migrating to alternative plugins like 'webpack-version-plugin' or use webpack.DefinePlugin with process.env.npm_package_version.
gotcha PACKAGE_JSON_INDENT default is 2, but example shows 4; mismatched indent may cause version file reformatting. ↓
fix Set PACKAGE_JSON_INDENT to match your package.json indent (usually 2) to avoid unwanted changes.
Install
npm install webpack-auto-inject-version yarn add webpack-auto-inject-version pnpm add webpack-auto-inject-version Imports
- WebpackAutoInject wrong
import WebpackAutoInject from 'webpack-auto-inject-version';correctconst WebpackAutoInject = require('webpack-auto-inject-version');
Quickstart
// webpack.config.js
const WebpackAutoInject = require('webpack-auto-inject-version');
module.exports = {
// ... webpack config
plugins: [
new WebpackAutoInject({
SHORT: 'CUSTOM',
SILENT: false,
PACKAGE_JSON_PATH: './package.json',
PACKAGE_JSON_INDENT: 4,
components: {
AutoIncreaseVersion: false,
InjectAsComment: true,
InjectByTag: true
},
componentsOptions: {
InjectAsComment: {
tag: 'Version: {version} - {date}',
dateFormat: 'h:MM:ss TT',
multiLineCommentType: false
},
InjectByTag: {
fileRegex: /\.+/,
AIVTagRegexp: /(\[AIV])(([a-zA-Z{} ,:;!()_@"'\\\/])+)(\[\/AIV])/g,
dateFormat: 'h:MM:ss TT'
}
}
})
]
};