美文网首页
npm简单实用

npm简单实用

作者: 来去匆匆不过过客 | 来源:发表于2017-07-30 01:31 被阅读0次

NPM(Node Package Manager)包管理和分发工具,下载、安装、上传、管理已安装的包
1.安装、更新和卸载

  • npm install 根据dependencies配置安装所有依赖包
  • npm install gulp 本地安装最新版本
  • npm install gulp -g 全局安装
  • npm uninstall 卸载
  • npm update 更新

2.查看npm

  • npm ls 查看已安装模块
  • npm version 查看模块版本
  • npm init 在项目中引导创建一个package.json文件
  • npm root [-g] 查看包的安装路径
  • npm view 查看模块注册信息

3.简单使用

  • npm cache clean 清除模块缓存
  • npm config 管理npm配置路径
//基础语法
npm config set [-g|--global]
npm config get
npm config delete
npm config list
npm config edit
npm get
npm set [-g|--global]
  • npm test [-- ] 测试模块
" script":{     //package.json文件scripts的test字段,可自定义执行一些操作
"test": "gulp release"
},
  • npm start [-- ] 启动模块
"script": {      //package.json文件script的start字段,命令行输入npm test及执行了gulpfile.js自定义的watch和server
"start": "gulp -ws"     //若无start字段,则启动node server.js
  • npm stop [-- ] 停止模块
  • npm restart [-- ] 重启模块
  • npm publish 发布模块

4.package.json文件

  • scripts
scripts {        //由脚本命令组成的hash对象,其中key为周期事件,value为要执行的命令
“key" : "value"
}
"scripts": {"start": "node server.js"}        //默认将start命令设置为node server.js
//若有wscript文件,默认将preinstall命令用node-waf编译
"scripts":{"preinstall": "node-waf clean || true; node-waf configure build"}
// 若有binding.gyp文件,默认将preinstall命令用node-gyp进行编译
"scripts":{"preinstall": "node-gyp rebuild"}
  • dependences 依赖包(hash值)
  • 其他的一些字段
    • name & version //必须存在的,name需要唯一
    • bugs //项目提交的url和邮箱
    • repository //指定代码存放位置

相关文章

网友评论

      本文标题:npm简单实用

      本文链接:https://www.haomeiwen.com/subject/tklhlxtx.html