美文网首页
NPM 笔记

NPM 笔记

作者: changhr2013 | 来源:发表于2022-04-29 14:53 被阅读0次

NPM 笔记

1. NPM 官网

https://www.npmjs.com

2. NPM 命令

2.1 快速初始化项目

npm init

2.2 查询 NPM 包

npm search coffee-script

2.3 安装 NPM 包

npm install coffee-script

2.3.1 安装到本地同时在 package.json 中添加依赖声明

npm install coffee-script --save

2.3.1 全局安装

npm install -g express-generator

2.4 查看当前全局安装的包

不加 -g 参数就是打印当前目录下 node_modules 文件夹下的包结构。

npm list -g

2.4.1 将目录树重定向到文件

npm list -g > d:\package.txt

2.5 卸载安装的包

npm uninstall express-generator -g

3. 淘宝镜像和 cnpm

3.1 安装 cnpm

npm install -g cnpm --registry=https://registry.npmmirror.com

3.2 切换淘宝镜像源

npm config set registry https://registry.npmmirror.com

3.3 更改 npm 默认安装路径

npm config set prefix "D:\npm"

设置完成后,记得将 d:\npm 添加到环境变量 PATH 中,否则在终端中无法找到全局安装的命令。

3.4 设置 npm 的缓存路径

npm config set cache "D:\npm-cache"

4. Yarn

4.1 与 npm 类似的命令

yarn init

yarn install

4.2 yarn 将依赖包安装到当前项目下,同时将配置写入 package.json

yarm add [package]

4.3 yarn 设置 cnpm 安装源

yran config set registry https://registry.npmmirror.com

4.4 yarn 设置安装包路径

设置完成后,记得将对应的 d:\yarn\global\bin添加到环境变量。

yarn config set global-folder "d:\yarn"

4.4.1 yarn 设置缓存路径

yarn config set cache-folder "d:\yarn_cache"

4.5 手动升级依赖包

yarn upgrade-interactive --latest

相关文章

  • NPM 笔记

    NPM 笔记 1. NPM 官网 https://www.npmjs.com[https://www.npmjs....

  • 无标题文章

    # javascript 笔记 ## 1 - confign (sudo) - node - npm init -...

  • npm 笔记

    How to Update Global Packages To update global packages, ...

  • 笔记 npm

    1. npm (node package management):node 的包管理 (1):Use npm to...

  • NPM笔记

    NPM笔记: 名字的含义: 1、是Node的开放式模块登记和管理系统 2、Node默认的模块管理器,是一个命令行下...

  • npm 笔记

    更新 npm 版本 -g 表示安装到全局目录。 npm 初始化 -y 表示所有配置选项使用默认值。 该命令会在目标...

  • npm 笔记

    换不了源 .npmrc 设置死了导致的 替换 registry npmrc npm runtime config ...

  • npm笔记

    基本命令 npm install 安装模块 若用了-S --save 则在package.json文件的depen...

  • markdown 生成目录

    1 有道云笔记目录生成 [toc] 2 使用 doctoc 工具生成目录 【需要npm 环境】 npm insta...

  • Vue开发的前期工作

    纯属个人笔记 npm init -y跳过询问并且初始化package.json文件 npm install -g ...

网友评论

      本文标题:NPM 笔记

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