Webpack Version File Plugin

0.1.7 · abandoned · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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' %>

view raw JSON →