Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuxt access git version or hash at build time and use in page

I have a Nuxt/Vue app that I am deploying through Netlify. I'm trying to inject the git version number and hash into the body of the page. I'm assuming there is a pretty straightforward way to do this (but I don't know what it is!).

like image 349
Zachary Russell Heineman Avatar asked Jan 26 '26 03:01

Zachary Russell Heineman


1 Answers

In package.json, you can pass the commit hash before call Nuxt:

"scripts": {
  "dev": "NUXT_ENV_CURRENT_GIT_SHA=`git rev-parse --short HEAD` nuxt",
  ...
},

Then, you can recover the value anywhere with process.env.NUXT_ENV_CURRENT_GIT_SHA.

like image 56
Juan Antonio Gómez Avatar answered Jan 27 '26 19:01

Juan Antonio Gómez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!