N
Nuxt2mo ago
Surreal

How to access buildId/build hash at runtime?

I've been trying to figure out how to access the build id/hash on the server side at runtime, so that I can build something from the client side to detect when a new version of my code has been released (e.g., expose the build hash via server API, periodically query it or build a websocket to monitor for change, etc.). Anyone know how to do this? The only things I've been able to find in this vein require either (1) hardcoding the buildId via config, or (2) intercepting, overriding, and storing the default hash generation in the "build:before" lifecycle hook. I'm hoping there's just a simpler, out-of-the-box way to access the existing generated ID. Thanks in advance!
2 Replies
dervondenbergen
dervondenbergen2mo ago
Are you looking for something like the app:manifest:update hook? From the Nuxt docs:
Called when there is a newer version of your app detected.
Behind the hook there is actually just a request to _nuxt/builds/latest.json and if the id changed, the hook gets triggered: https://github.com/nuxt/nuxt/blob/f78da087df40e08f2e9239be10a11a75fac07db8/packages/nuxt/src/app/plugins/check-outdated-build.client.ts You can also define the interval, if the default one of 1 hour is not fitting: https://nuxt.com/docs/api/nuxt-config#checkoutdatedbuildinterval
GitHub
nuxt/packages/nuxt/src/app/plugins/check-outdated-build.client.ts a...
The Intuitive Vue Framework. Contribute to nuxt/nuxt development by creating an account on GitHub.
Nuxt
Nuxt Configuration
Discover all the options you can use in your nuxt.config.ts file.
Surreal
Surreal2mo ago
Oh interesting! Hadn't seen that hook before, will have to take a look - thanks!
Want results from more Discord servers?
Add your server