update package.json version automatically

后端 未结 12 2065
长发绾君心
长发绾君心 2020-12-02 04:37

Before I do a small release and tag it, I\'d like to update the package.json to reflect the new version of the program.

Is there a way to edit the file package

12条回答
  •  不思量自难忘°
    2020-12-02 04:54

    I am using husky and git-branch-is:

    As of husky v1+:

    // package.json
    {
      "husky": {
        "hooks": {
          "post-merge": "(git-branch-is master && npm version minor || 
      (git-branch-is dev && npm --no-git-tag-version version patch)",
        }
      }
    }
    

    Prior to husky V1:

    "scripts": {
      ...
      "postmerge": "(git-branch-is master && npm version minor || 
      (git-branch-is dev && npm --no-git-tag-version version patch)",
      ...
    },
    

    Read more about npm version

    Webpack or Vue.js

    If you are using webpack or Vue.js, you can display this in the UI using Auto inject version - Webpack plugin

    NUXT

    In nuxt.config.js:

    var WebpackAutoInject = require('webpack-auto-inject-version');
    
    module.exports = {
      build: {
        plugins: [
          new WebpackAutoInject({
            // options
            // example:
            components: {
              InjectAsComment: false
            },
          }),
        ]
      },
    }
    

    Inside your template for example in the footer:

    All rights reserved © 2018 [v[AIV]{version}[/AIV]]

提交回复
热议问题