How do I add comments to package.json for npm install?

后端 未结 20 1389
悲哀的现实
悲哀的现实 2020-12-07 07:30

I\'ve got a simple package.json file and I want to add a comment. Is there a way to do this, or are there any hacks to make this work?



        
20条回答
  •  天涯浪人
    2020-12-07 08:02

    After wasting an hour on complex and hacky solutions, I've found both simple and valid solution for commenting my bulky dependencies section in package.json. Just like this:

    {
      "name": "package name",
      "version": "1.0",
      "description": "package description",
      "scripts": {
        "start": "npm install && node server.js"
      },
      "scriptsComments": {
        "start": "Runs development build on a local server configured by server.js"
      },
      "dependencies": {
        "ajv": "^5.2.2"
      },
      "dependenciesComments": {
        "ajv": "JSON-Schema Validator for validation of API data"
      }
    }
    

    When sorted the same way, it's now very easy for me to track these pairs of dependencies/comments either in Git commit diffs or in an editor while working with file package.json.

    And no extra tools are involved, just plain and valid JSON.

提交回复
热议问题