NPM创建项目

4,769 阅读1分钟
  1. 使用npm创建项目
  2. npm init命令详解
  3. package.json配置详解

1.使用npm创建项目

​ 在一个空文件夹下,使用powershell切换到该目录,完成后会生成一个package.json的配置文件。

# 项目初始化
npm init
# 使用默认设置初始化项目
npm init -y

2.npm init详解

  • name 项目名称
  • version 项目版本号
  • description 项目描述信息
  • entry point 项目入口文件
  • test command 项目启动的脚本命令
  • git repository 如果你有 Git 地址,可以将这个项目放到你的 Git 仓库里
  • keywords 关键词
  • author 作者
  • license 项目要发行的时候需要的证书,平时往往忽略

3.package.json详解

"private": true,
"dependencies": {
	"antd": "^2.11.1",
	"classnames": "^2.2.5"
},
"devDependencies": {
	"axios": "^0.15.3",
	"babel-eslint": "^6.1.2"
},
"bin": {
	"dk-cli": "./bin/dk-cli.js"
},
"scripts": {
	"start": "node index.js"
},
"engines": {
	"node": ">=6.9.0",
	"npm": ">=3.10.10"
}
"publishConfig": {
	"registry": "http://gongsineibu/nexus/repository/npm-hosted/"
}
  • private(boolearn) 是否私有,为true,npm会拒绝发布
  • dependencies && devDependencies(development Dependencies)
    • dependencies 生产依赖(项目发布后仍需要用到的模块,例如jQuery)
    • devDependencies 开发依赖(开发时使用的模块,不需要发布到线上)
  • bin npm 命令行工具
  • scripts 脚本命令(例如npm start 会自动在命令行中输入 node index.js)
  • engines 项目所依赖模块的版本信息
  • publishConfig 将包发布到NPM仓库(可以使用自定义地址)

整理自dkvirus的通俗易懂的 Npm入门教程