feat: Inject package.json version into the app

This commit is contained in:
Bastien Wirtz
2025-09-29 21:53:11 +02:00
parent 4904717db0
commit 81c7496264
3 changed files with 24 additions and 2 deletions

View File

@@ -6,7 +6,14 @@ import eslintConfigPrettier from "@vue/eslint-config-prettier";
/** @type {import('eslint').Linter.Config[]} */
export default [
{ files: ["**/*.{js,mjs,cjs,vue}"] },
{ languageOptions: { globals: globals.browser } },
{
languageOptions: {
globals: {
...globals.browser,
__APP_VERSION__: "readable",
},
},
},
pluginJs.configs.recommended,
...pluginVue.configs["flat/recommended"],
eslintConfigPrettier,

View File

@@ -54,7 +54,6 @@
/>
</Navbar>
</div>
<section id="main-section" class="section">
<div v-cloak class="container">
<ConnectivityChecker
@@ -154,6 +153,7 @@ export default {
this.buildDashboard();
window.onhashchange = this.buildDashboard;
this.loaded = true;
console.info(`Homer v${__APP_VERSION__}`);
},
beforeUnmount() {
window.onhashchange = null;

View File

@@ -7,13 +7,28 @@ import process from "process";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { version } from "./package.json";
function writeVersionPlugin() {
return {
name: "write-version",
closeBundle() {
fs.writeFileSync("dist/VERSION", version);
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
base: "",
build: {
assetsDir: "resources",
},
define: {
__APP_VERSION__: JSON.stringify(version),
},
plugins: [
writeVersionPlugin(),
// Custom plugin to serve dummy-data JSON files without sourcemap injection
{
name: "dummy-data-json-handler",