3

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

Can this be done?

Fernando
  • 325
  • 2
  • 13

1 Answers1

13

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 can use the variable, inside your components with $config.clientVersion

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

Mattia Galati
  • 2,415
  • 16
  • 22