N
Nuxt5mo ago
asasinmode

Read and set a value to use inside of template during build time

I want to access my project's version inside my template, the "version" field in package.json. I'd like to get it programmatically instead of having to manually update it, since it's going to be updated with bumpp on releases. Is it possible for me to make nuxt, at some point in the build step (and ideally in dev too) read package.json file then set like useRuntimeConfig().public.appVersion?
2 Replies
Ferrington
Ferrington5mo ago
You can import your package.json and add a property to nuxt.config.ts
import pkg from "./package.json";

export default defineNuxtConfig({
appConfig: {
appVersion: pkg.version,
},
})
import pkg from "./package.json";

export default defineNuxtConfig({
appConfig: {
appVersion: pkg.version,
},
})
Then access it like useAppConfig().appVersion
asasinmode
asasinmodeOP5mo ago
Thanks, it works
Want results from more Discord servers?
Add your server