vite-plugin-build-metadata
v0.5.0
Published
Create Vite build meta
Downloads
132
Readme
💙 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