npm 是前端最常用也是最容易被忽视的一个工具,下面是一些与npm命令有关的冷知识。
npm install -S 是 npm install --save 的简写,写入到 dependencies 对象。
npm install -D 是 npm install --save-dev 的简写,写入到 devDependencies 对象。-D 必须要大写才能有效
npm i 是 npm install 的简写。
npm install -g 用来安装全局模块。
删除模块使用 npm uninstall <name>
删除全局模块 npm uninstall -g <name>
npm la 查看完整的项目模块依赖。
npm ls --depth=0 查看当前模块依赖哪些包,不包括依赖的依赖。
npm init --yes 初始化一个npm模块,快速执行默认设置,不用一路按 Enter 键。
npm install 命令执行完成之后会生成一个 packager-lock.json 文件。
npm 切换淘宝源 npm config set registry https://registry.npm.taobao.org
npm cache clean 命令在现在的版本已经被废弃了,执行该命令的时候,会有如下的提示
$ npm cache clean
npm ERR! As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one.
npm ERR!
npm ERR! If you're sure you want to delete the entire cache, rerun this command with --force.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2019-09-06T02_35_20_337Z-debug.log
npm config set prefix "D:\Program Files\nodejs\X64\node_global" 设置npm全局安装程序时的目录前缀
npm config set cache "D:\Program Files\nodejs\X64\node_cache" 设置npm安装程序时的缓存位置
npm ls -g --depth=0 可以查看全局安装了那些模块。