vite-plugin-version-json
v0.0.1
Published
Generate a version.json file based on the version number of the package.json file and support custom configuration.
Downloads
7
Maintainers
Readme
vite-plugin-version-json
Generate a version.json file based on the version number of the package.json file and support custom configuration.
Install
# yarn
yarn add vite-plugin-version-json -D
# npm
npm install vite-plugin-version-json --save-devUsage
// vite.config.js
import { defineConfig } from 'vite';
import { vitePluginVersionJson } from 'vite-plugin-version-json';
export default defineConfig({
plugins: [vitePluginVersionJson()]
})Options
Properties of the options Object
| Property Name | Type | Required | Description |
|----------------|---------|--------|-----------|
| filename | string | No | Path of the generated JSON file. Defaults to version.json under the build output directory. |
| title | string | No | Title field in the generated JSON file; defaults to an empty string. |
| message | string | No | Message field in the generated JSON file; defaults to an empty string. |
| timestamp | number | No | Timestamp field in the generated JSON file; defaults to current timestamp (Date.now()). |
| version | string | No | Version number field in the generated JSON file. If not provided, it will be read from package.json; if no version exists there, a timestamp will be used as the version. |
| extra | any | No | Additional field in the generated JSON file; can be any type; defaults to undefined. |
Example
vitePluginVersionJson({
filename: 'version.json',
title: 'New version',
message: 'New version message.',
timestamp: Date.now(),
version: '1.0.0',
extra: { environment: 'production' },
});The above configuration will generate a version.json file with the following content:
{
"title": "New version",
"message": "New version message.",
"timestamp": 1749484800000,
"version": "1.0.0",
"extra": {
"environment": "production"
}
}