npm-init

创建一个package.json文件

概要

npm init [-f|--force|-y|--yes]

描述

输入命令,会提出一堆问题,回答以后,根据回答创建package.json文件。

> npm init
# 一堆提问,省略

如果你已经有了一个package.json文件,他会读取上面的信息作为默认选项。

如果加上了这些参数-f,--force 或者 -y,--yes 则不会提出问题,并生成带默认信息的package.json文件。

> npm init -f

# package.json自动生成如下信息
{
  "name": "npm-demos-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "ag_dubs <[email protected]>",
  "license": "ISC"
}

配置

scope
  • 默认:none
  • 类型:String

给包名添加一个命名空间,主要是给package.json中的name属性添加命名空间。

> npm init --scope=username

# package.json文件,注意name属性。
{
  "name": "@username/npm-demos-test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "ag_dubs <[email protected]>",
  "license": "ISC",
  "description": ""
}

请包发布者注意:上面username最好使用当前的登录账户,可通过npm whoami查看当前账户。

results matching ""

    No results matching ""