Search code examples
versionpackage.jsonnuxt.js

Show package.json version on NuxtJS application


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

Can this be done?


Solution

  • 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