Show package.json version on NuxtJS application

Viewed 1104

I want to use the version number that is configured on package.json into my components on NuxtJS application.

Can this be done?

1 Answers

At the top of your nuxt.config.js file put an import

import pkg from './package.json'

then, inside the same file, insert this part

export default {
  ...
  // https://nuxtjs.org/guide/runtime-config
  publicRuntimeConfig: {
    clientVersion: pkg.version,
  }
}

Now you canf use the veriable, inside your components with $config.clientVersion

For more details, see the docs at https://nuxtjs.org/guide/runtime-config

Related