如何向 package.json 添加注释以进行 npm 安装? [英] How do I add comments to package.json for npm install?

查看:23
本文介绍了如何向 package.json 添加注释以进行 npm 安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 package.json 文件,我想添加评论.有没有办法做到这一点,或者是否有任何技巧可以使这项工作发挥作用?

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?

{
  "name": "My Project",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "3.x",
    "mongoose": "3.x"
  },
  "devDependencies" :  {
    "should": "*"
    /* "mocha": "*" not needed as should be globally installed */
  }
}

上面的示例注释在 npm 中断时不起作用.我也试过//样式注释.

The example comment above doesn't work as npm breaks. I've also tried // style comments.

推荐答案

最近在 Node.js 邮件列表.

根据创建 npm 的 Isaac Schlueter 的说法:

According to Isaac Schlueter who created npm:

...//"键永远不会被 npm 用于任何目的,并保留用于注释......如果你想使用多行注释,你可以使用一个数组,或者多个//";键.

... the "//" key will never be used by npm for any purpose, and is reserved for comments ... If you want to use a multiple line comment, you can use either an array, or multiple "//" keys.

在使用常用工具(npm、yarn 等)时,多个//";键将被删除.这幸存下来:

When using your usual tools (npm, yarn, etc.), multiple "//" keys will be removed. This survives:

{ "//": [
  "first line",
  "second line" ] }

这将无法生存:

{ "//": "this is the first line of a comment",
  "//": "this is the second line of the comment" }

这篇关于如何向 package.json 添加注释以进行 npm 安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆