Registry / devops / webpack-version-file

webpack-version-file

JSON →
library0.1.7jsnpmunverified

This Webpack plugin, `webpack-version-file`, generates a file (typically `version.txt`) containing crucial project metadata such as the package name, version number, and build date during the Webpack compilation process. It is particularly useful for tracking which version of an application is deployed in various environments, aiding in debugging and support. The plugin, currently at version `0.1.7` (last updated in 2017), is considered abandoned. It utilizes EJS for templating, allowing extensive customization of the output file's content using data from `package.json`, predefined variables like `buildDate`, and custom data passed via its options. Its simplicity and direct integration into the Webpack build lifecycle were its key differentiators, though its lack of maintenance is a significant concern for modern Webpack and Node.js environments.

npm install webpack-version-file
INSTALL
IMPORT
SIG · WEBPACK-VERSION-FI
W
webpack-version-file
devopsjavascriptv0.1.7
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

VersionFile
✓ const VersionFile = require('webpack-version-file');
✗ import VersionFile from 'webpack-version-file';
This plugin is distributed as a CommonJS module. Direct ESM import via 'import' statements may not work without a CommonJS wrapper or specific bundler configuration in modern pure ESM environments.
new VersionFile()
✓ new VersionFile({ output: './build/version.txt' })
✗ VersionFile();
The plugin is a class and must be instantiated with the 'new' keyword when added to the Webpack plugins array.

Demonstrates how to configure `webpack-version-file` in a Webpack setup, generating a `version.txt` file alongside your bundle with project metadata and custom environment data using a custom EJS template.

const path = require('path'); const VersionFile = require('webpack-version-file'); module.exports = { entry: './src/index.js', // Your application's entry point output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, plugins: [ new VersionFile({ output: path.resolve(__dirname, 'dist', 'version.txt'), package: path.resolve(__dirname, 'package.json'), template: './version.ejs', // Path to your custom EJS template file data: { buildUser: process.env.USER ?? 'anonymous', gitCommit: process.env.GITHUB_SHA ?? 'N/A' }, verbose: true, }) ], mode: 'development' // or 'production' }; // To run this example, create a file named 'version.ejs' in your project root: // <%= name %>@<%= version %> // Built by: <%= buildUser %> // Commit: <%= gitCommit %> // Build date: <%= buildDate %> // License: <%= license %> // Environment: <%= process.env.NODE_ENV ?? 'development' %>
Debug
Known issues
gotchaThe 'webpack-version-file' package has not been updated in over seven years (last release 0.1.7 in 2017) and is considered abandoned. It may not be compatible with recent Webpack versions (v5+) or modern Node.js environments, and will not receive security patches or bug fixes.
fix
Consider alternative solutions for injecting version information, such as Webpack's built-in `webpack.DefinePlugin` for in-bundle definitions, or more actively maintained version file generation plugins. Alternatively, fork the repository and maintain it yourself if its specific features are critical.
affects: All
gotchaThis plugin is a CommonJS module and uses `require()`. Directly importing it using ES Modules `import` syntax in a pure ESM environment may lead to errors without proper Webpack configuration (e.g., using `resolve.fallback` for Node.js built-ins) or a CommonJS wrapper.
fix
Always use `const VersionFile = require('webpack-version-file');` in your Webpack configuration file. Ensure your Webpack configuration is set up to correctly handle CommonJS modules, especially if your project primarily uses ESM.
affects: All
gotchaThe plugin relies on EJS templating. Ensure template syntax is correct, and all variables referenced (e.g., `<%= variable %>`) are either derived from `package.json`, predefined (`buildDate`), or explicitly passed via the `data` option. Unresolved variables will render as empty or undefined in the output.
fix
Verify EJS template syntax is correct. Cross-reference all template variables with the fields available in your `package.json`, the predefined `buildDate`, and any custom data provided in the `data` option. Temporarily simplify your template or log the `data` object to debug rendering issues.
affects: All
Errors
Common errors & fixes
TypeError: Class constructor VersionFile cannot be invoked without 'new'
Attempting to call the plugin constructor `VersionFile()` directly without the `new` keyword.
fix
Ensure you instantiate the plugin using `new VersionFile()` within your Webpack plugins array in `webpack.config.js`.
Module not found: Error: Can't resolve 'webpack-version-file' in '...'
The `webpack-version-file` package is not installed as a development dependency, or Webpack cannot locate it in `node_modules`.
fix
Run `npm install --save-dev webpack-version-file` or `yarn add --dev webpack-version-file` in your project's root directory to install the package.
Error: ENOENT: no such file or directory, open '...' (for 'package' or 'template' option)
The path specified for the `package` or `template` option in the plugin configuration is incorrect, or the file does not exist at the given path.
fix
Verify that the file paths provided to the `package` and `template` options are correct and accessible. It's best practice to use `path.resolve(__dirname, 'file.json')` for robust, absolute path resolution.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies
webpackrequiredThis is a Webpack plugin and requires Webpack as a peer dependency to function.
Agent activity
6 hits · last 30 days
node
6
Resources
webpack-version-file — npm install webpack-version-file · libregistry