Get the version
information from package.json
, then automatically put the version file version.json
in your project dist folder when packaging.
// package.json
{
// ...
"version": "0.0.1"
}
// dist/version.json
{
"version": "0.0.1"
}
npm i vite-plugin-version
Add plugin to your vite.config.ts
:
// vite.config.ts
import { defineConfig } from 'vite'
import versionPlugin from 'vite-plugin-version'
export default defineConfig({
plugins: [
versionPlugin(),
],
})