This template helps you get started with Vue 3 in Vite, and demonstrates how to dynamically generate and use a version.json
file containing your app's version and git info.
This project includes a custom Vite plugin that:
- Reads version info from
package.json
and git (tag, commit hash, timestamp) - Injects compile-time constants (
import.meta.env.APP_VERSION
,import.meta.env.APP_TAG
) - Serves
/version.json
dynamically during development - Emits
dist/version.json
after build
- Install dependencies:
npm install
- Run in development:
npm run dev
- Visit the app to see version info from both compile-time and runtime
- Or visit
/version.json
directly in your browser
- Build for production:
npm run build
- After build,
dist/version.json
will contain the version info
- After build,
- Access version info in your app:
- Compile-time: Use
import.meta.env.APP_VERSION
andimport.meta.env.APP_TAG
- Runtime: Fetch
/version.json
(e.g.,fetch('/version.json')
)
- Compile-time: Use
VSCode + Volar (and disable Vetur).
TypeScript cannot handle type information for .vue
imports by default, so we replace the tsc
CLI with vue-tsc
for type checking. In editors, we need Volar to make the TypeScript language service aware of .vue
types.
See Vite Configuration Reference.
npm install
npm run dev
npm run build
Lint with ESLint
npm run lint