yarn npm link 命令解析

npm和yarn的区别

yarn客户端包官网地址:https://yarnpkg.com/en/docs/install#windows-stable html

在win环境下使用yarn安装 vue-cli

 

0.安装  (没装npm的时候也能够用客户端安装 :https://yarnpkg.com/en/docs/install#windows-stable )vue

npm install -g yarn

显示全局包位置: yarn global dirnode

设置缓存文件夹 位置  yarn config set cache-folder c:\yarn\cachenginx

设置全局包位置:  1. you need to add the line --global-folder "C:\ds_raiser\common\yarn\data\global"manually into your .yarnrc file.git

                            2.    直接用这句命令不起做用  yarn config set global-folder "C:\ds_raiser\common\yarn\data\global    参考:https://github.com/yarnpkg/yarn/issues/5746github

 关于npm和yarn的全局包位置务必看下这个 ****** 记一次npm 和 yarn 安装的折腾web

一、初始化一个新的项目vue-cli

yarn init

二、添加一个依赖包docker

yarn add [package] yarn add [package]@[version] yarn add [package]@[tag]

三、安装全部的依赖包npm

yarn 或者 yarn install

 

改源:https://blog.csdn.net/p358278505/article/details/72916548 

yarn config set registry https://registry.npm.taobao.org

查看

yarn config get registry

 

四、npm 与 yarn命令比较

 

NPM YARN 说明
npm init yarn init 初始化某个项目
npm install/link yarn install/link 默认的安装依赖操做
npm install taco —save yarn add taco 安装某个依赖,而且默认保存到package.
npm uninstall taco —save yarn remove taco 移除某个依赖项目
npm install taco —save-dev yarn add taco —dev 安装某个开发时依赖项目
npm update taco —save yarn upgrade taco 更新某个依赖项目
npm install taco --global yarn global add taco 安装某个全局依赖项目
npm publish/login/logout yarn publish/login/logout 发布/登陆/登出,一系列NPM Registry操做
npm run/test yarn run/test 运行某个命令
npm config ls yarn global dir 显示yarn安装路径
     
 

CLI commands comparison

npm (v5) Yarn
npm install yarn install
(N/A) yarn install --flat
(N/A) yarn install --har
npm install --no-package-lock yarn install --no-lockfile
(N/A) yarn install --pure-lockfile
npm install [package] --save yarn add [package]
npm install [package] --save-dev yarn add [package] --dev
(N/A) yarn add [package] --peer
npm install [package] --save-optional yarn add [package] --optional
npm install [package] --save-exact yarn add [package] --exact
(N/A) yarn add [package] --tilde
npm install [package] --global yarn global add [package]
npm update --global                   yarn global upgrade                    
npm rebuild yarn add --force
npm uninstall [package] yarn remove [package]
npm cache clean yarn cache clean [package]
rm -rf node_modules && npm install   yarn upgrade                          
npm version major                     yarn version --major                  
npm version minor                     yarn version --minor                  
npm version patch                     yarn version --patch                  
 

 

npm link 命令解析

 文字转的

对开发者而言,这算是最有价值的命令。假设咱们开发了一个模块叫 test ,而后咱们在 test-example 里引用这个模块 ,每次 test 模块的变更咱们都须要反映到 test-example 模块里。不要担忧,有了 npm link 命令一切变的很是容易。

首先咱们须要把 test 连接到全局模式下:

cd ~/work/node/test # 进入test模块目录
npm link # 建立连接到$PREFIX/lib/node_modules

那么 test 的模块将被连接到 $PREFIX/lib/node_modules 下,就像个人机器上 $PREFIX 指到 /usr/local ,那么 /usr/local/lib/node_modules/test 将会连接到 ~/work/node/test 下。执行脚本 bin/test.js 被连接到 /usr/local/bin/test 上。

接下来咱们须要把 test 引用到 test-example 项目中来:

cd ~/work/node/test-example # 进入test-example模块目录
npm link test # 把全局模式的模块连接到本地

npm link test 命令会去 $PREFIX/lib/node_modules 目录下查找名叫 test 的模块,找到这个模块后把 $PREFIX/lib/node_modules/test 的目录连接到 ~/work/node/test-example/node_modules/test 这个目录上来。

如今任何 test 模块上的改动都会直接映射到 test-example 上来。

 

再好比假设咱们开发不少应用,每一个应用都用到 Coffee-script :

npm install coffee-script -g # 全局模式下安装coffee-script
cd ~/work/node/test # 进入开发目录
npm link coffee-script # 把全局模式的coffee-script模块连接到本地的node_modules下
cd ../test-example # 进入另外的一个开发目录
npm link coffee-script # 把全局模式的coffee-script模块连接到本地
npm update coffee-script -g # 更新全局模式的coffee-script,全部link过去的项目同时更新了。

yarn 国内加速,修改镜像源


yarn config set registry https://registry.npm.taobao.org

相关文章
相关标签/搜索