npm概念
npm
是什么
node package manager:node包管理工具
为什么要使用npm
安装第三方库:https://www.npmjs.com/
使用第三方库的时候需要先安装,安装后,才能使用第三方库
怎么用
npm install *** (npm i ***) 安装包 下载安装在当前目录下node_modules特殊文件夹中。当前目录是输入cmd时,cmd显示的目录
npm unistall *** (npm un ***) 删除包
导入包,请使用require()
npm init
功能 creating a package.json file. 初始化package.jso文件,
该文件是项目工程文件,以后需要使用npm进行管理的项目都会需要有这样一个文件
npm init --yes(npm init -y)
快速生成package.json文件
npm install(i) 包 npm install 包1 包2 包3 ... npm install 包@版本号 npm list 查看当前项目安装的所有依赖以及它们依赖的模块 npm list --global npm update 包名 npm unistall 包名 npm view(v/info/show) 包 npm 命令 --help npm install 一次安装dependencies中所有的依赖项
换源
国外网站请求比较慢,用国内的
使用淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm install jquery --registry=https://registry.npm.taobao.org
每次手动加--registry=https://registry.npm.taobao.org很麻烦 可以通过修改配置文件来处理
npm config set registry https://registry.npm.taobao.org
npm i jquery
注意:有些包必须用npm下载,如果使用cnpm下载的包使用时有问题,请使用npm下载后试试