From 47cf3834897a54512c842dfbb75c6205a4663ceb Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Thu, 5 Sep 2024 20:16:01 +0200 Subject: [PATCH] Set version through `process.env` --- src/store/auth.js | 5 +++-- src/version.js | 1 - vue.config.js | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) delete mode 100644 src/version.js diff --git a/src/store/auth.js b/src/store/auth.js index 53503a36a..035faca1f 100644 --- a/src/store/auth.js +++ b/src/store/auth.js @@ -1,7 +1,6 @@ import Vue from "vue"; import api from "@/api"; import { fetchAll } from "./actions"; -import { APPLICATION_VERSION } from "../version"; export default { namespaced: true, @@ -58,7 +57,9 @@ export default { async login({ commit }, data) { try { const result = await api.auth_tokens.create({ - auth_token: { application: APPLICATION_VERSION }, + auth_token: { + application: process.env.APPLICATION_VERSION, + }, ...data, }); commit("login", result); diff --git a/src/version.js b/src/version.js deleted file mode 100644 index ebbe83d4a..000000000 --- a/src/version.js +++ /dev/null @@ -1 +0,0 @@ -export const APPLICATION_VERSION = `WEB v${require("../package.json").version}`; diff --git a/vue.config.js b/vue.config.js index 9014242bd..31a8281f2 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,3 +1,6 @@ +const version = require("./package.json").version; +const webpack = require("webpack"); + module.exports = { pluginOptions: { i18n: { @@ -16,6 +19,14 @@ module.exports = { }, configureWebpack: (config) => { config.cache = process.env.SKIP_CACHE !== "true"; + config.plugins.push( + new webpack.DefinePlugin({ + "process.env": { + // When building, this value will just be printed without quotes, so we add them explicitly + APPLICATION_VERSION: `"Accentor Web v${version}"`, + }, + }), + ); }, chainWebpack: (config) => { config.module @@ -24,7 +35,7 @@ module.exports = { .tap((opt) => Object.assign(opt, { cacheDirectory: process.env.SKIP_CACHE !== "true", - }), + }) ); config .plugin("eslint") @@ -39,7 +50,7 @@ module.exports = { .tap((opt) => Object.assign(opt, { additionalData: `@import '~@/sass/main.scss';`, - }), + }) ); }); },