vite-plugin-build-metadata
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

vite-plugin-build-metadata

Create Vite build meta


💙 SPECIAL SPONSOR

Usage

Installation

Install the vite-plugin-build-metadata package as a development dependency using pnpm:

pnpm i vite-plugin-build-metadata -D

Configuration

Add the plugin to your vite.config.js file:

// vite.config.js
import VitePluginBuildMetadata from 'vite-plugin-build-metadata';

export default {
  plugins: [
    VitePluginBuildMetadata(),
  ],
};

Once the plugin is installed and configured, it will generate a file in the root build directory (default filename: meta.json) after each build. This file will contain the following information:

{
  "buildHash": "GENERATED_BUILD_HASH",
  "commitHash": "LAST_COMMIT_HASH",
  "date": "BUILD_DATE"
}

You can customize the filename by passing an options object to the VitePluginBuildMetadata constructor:

// vite.config.js
import VitePluginBuildMetadata from 'vite-plugin-build-metadata';

export default {
  plugins: [
    VitePluginBuildMetadata({ filename: 'custom-meta.json' }), // or without .json extension
  ],
};

Motivation

The vite-plugin-build-metadata plugin provides a way to determine the relevance of the deployed version of a frontend application. By including build and commit hashes, as well as the build date, in the generated metadata file, you can easily track and verify the version of your application in production.

This information can be useful in various scenarios, such as:

  • Ensuring that the correct version of the application is deployed in production environments.
  • Debugging issues by identifying the specific build and commit associated with a deployed version.
  • Comparing different builds to track changes and assess their impact.

Including build metadata in your frontend builds adds an extra layer of transparency and accountability to your development process.

License

MIT License © 2021 Daniil Chumachenko

Readme

Keywords

Package Sidebar

Install

npm i vite-plugin-build-metadata

Weekly Downloads

32

Version

0.4.0

License

MIT

Unpacked Size

9.78 kB

Total Files

7

Last publish

Collaborators

  • daniil4udo