zoukankan      html  css  js  c++  java
  • yarn

    npm和yarn的区别

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

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

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

    npm install -g yarn

    显示全局包位置: yarn global dir

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

    设置全局包位置:  1. you need to add the line --global-folder "C:ds_raisercommonyarndataglobal"manually into your .yarnrc file.

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

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

    1、初始化一个新的项目

    yarn init

    2、添加一个依赖包

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

    3、安装所有的依赖包

    yarn 或者 yarn install

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

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

    查看

    yarn config get registry

    4、npm 与 yarn命令比较

    NPMYARN说明
    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

  • 相关阅读:
    Python-OpenCV——进阶操作一网打尽
    深入理解jQuery插件开发
    Bootstrap整合ASP.NET MVC验证、jquery.validate.unobtrusive
    实用的Bootstrap的扩展和插件集合
    hadoop编程小技巧(5)---自定义输入文件格式类InputFormat
    mapreduce作业状态一直是ACCEPTED
    hadoop CLASSNAME命令使用注意点
    运行java的class文件方法详解
    Hadoop、Zookeeper、Hbase分布式安装教程
    java enum(枚举)使用详解 + 总结
  • 原文地址:https://www.cnblogs.com/lhuser/p/11062945.html
Copyright © 2011-2022 走看看