1.0.10 • Published 2 years ago
@credenceanalytics/inject-vue-app-version v1.0.10
Installation
npm i -D @credenceanalytics/inject-vue-app-versionHow to inject a app version in vue application ?
- Install
@credenceanalytics/inject-vue-app-versionpackage from npm repository. - Create
version.txtfile in your appyour_app > current_app_version > version.txt - Now import
@credenceanalytics/inject-vue-app-versionpackage in yourvue.config.jsfile at line no.1.
// vue.config.js
require("@credenceanalytics/inject-vue-app-version");
...- This package injects a
VUE_APP_VERSIONin to environment variables. VUE_APP_VERSIONconsists a build time (current date and time) and git branch name (current branch name).version.txtwill get updated withVUE_APP_VERSIONversion value.- To print app version in browser, add this line
console.log("%c" + process.env.VUE_APP_VERSION, "color:blue;font-size: 14px;font-weight: 700")in mounted or created hook of your entry vue file.
// App.vue
export default {
name: 'app',
components: {
...
},
created() {
console.log("%c" + process.env.VUE_APP_VERSION, "color:blue;font-size: 14px;font-weight: 700")
},
mounted (){
...
}
}Example
- First create a directory
current_app_versionin your root project with emptyversion.txtfile. - Now in your
vue.config.jsrequire this library.
// vue.config.js
require("@credenceanalytics/inject-vue-app-version");
...- Print the version in your entry component file i.e in
src/App.vue.
// App.vue
<template>
...
</template>
<script>
export default {
name: "app",
...,
created() {
...
console.log("%c" + process.env.VUE_APP_VERSION, "color:blue;font-size: 14px;font-weight: 700")
}
}
</script>