yarn详细入门教程

Yarn简介

Yarn 是 Facebook, Google, Exponent 和 Tilde 开发的一款新的 JavaScript 包管理工具。就像我们可以从官方文档了解那样,它的目的是解决这些团队使用 npm 面临的少数问题.

一键安装

官网脚本:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly

或者:

最简单的方法是运行:

npm install -g yarn

现在的yarn安装页面是这么说的:

注意:通常情况下不建议通过npm进行安装。npm安装是非确定性的,程序包没有签名,并且npm除了做了基本的SHA1哈希之外不执行任何完整性检查,这给安装系统程序带来了安全风险。

基于这些原因,强烈建议你通过最适合于你的操作系统的安装方法来安装yarn。

以这种速度发展下去的话,如果yarn要宣布他们自己的registry,让开发者慢慢淘汰npm的话,我们一点都不会感到惊讶。

安装成功后即可查看版本:

yarn –version

常用命令

初始化一个新项目

yarn init

添加依赖包

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

将依赖项添加到不同依赖项类别中

分别添加到 devDependencies、peerDependencies 和 optionalDependencies 类别中:

yarn add [package] --dev
yarn add [package] --peer
yarn add [package] --optional

升级依赖包

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

移除依赖包

yarn remove [package]

安装项目的全部依赖

yarn

或者

yarn install

例如:

$ yarn install
yarn install v1.13.0-20181121.1436
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > babel-jest@23.6.0" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-0".
[4/4] 📃  Building fresh packages...
$ lerna bootstrap
lerna notice cli v3.4.3
lerna info Bootstrapping 5 packages
lerna info Installing external dependencies
lerna info Symlinking packages and binaries
lerna success Bootstrapped 5 packages
✨  Done in 271.39s.

$ yarn build
yarn run v1.13.0-20181121.1436
$ lerna run build --ignore selenium-ide-extension-boilerplate
lerna notice cli v3.4.3
lerna info filter [ '!selenium-ide-extension-boilerplate' ]
lerna info Executing command in 4 packages: "yarn run build"
$ yarn run browserify src/index.js -s browser-webdriver -o build/webdriver.js
$ /Users/jack/ui/selenium-ide/packages/browser-webdriver/node_modules/.bin/browserify src/index.js -s browser-webdriver -o build/webdriver.js
$ rollup -c
$ babel -d dist src --ignore=__test__
src/capabilities.js -> dist/capabilities.js
src/child.js -> dist/child.js
src/config.js -> dist/config.js
src/index.js -> dist/index.js
src/npm.js -> dist/npm.js
src/versioner.js -> dist/versioner.js
$ rm -rf build && env NODE_ENV=production webpack
Hash: 5f687715a247631dc1c4
Version: webpack 3.12.0
Time: 108660ms
                                      Asset       Size  Chunks                    Chunk Names
                              escape.js.map    14.2 kB       6  [emitted]         escape
media/selenium_blue_white32@3x.84ab23d0.svg    3.62 kB          [emitted]         
            media/selenium-ide.9b39b00c.svg    21.8 kB          [emitted]         
                                playback.js    99.7 kB       0  [emitted]         playback
                                  record.js    39.4 kB       1  [emitted]         record
                                     neo.js    2.43 MB       2  [emitted]  [big]  neo
                                   atoms.js     494 kB       3  [emitted]  [big]  atoms
                              background.js      12 kB       4  [emitted]         background
                               polyfills.js    7.15 kB       5  [emitted]         polyfills
                                  escape.js    2.99 kB       6  [emitted]         escape
                            playback.js.map     387 kB       0  [emitted]         playback
                              record.js.map     162 kB       1  [emitted]         record
                                 neo.js.map    8.53 MB       2  [emitted]         neo
                               atoms.js.map    2.23 MB       3  [emitted]         atoms
                          background.js.map    54.8 kB       4  [emitted]         background
                           polyfills.js.map    40.6 kB       5  [emitted]         polyfills
            media/selenium-ide.461193c2.ttf    7.44 kB          [emitted]         
                           vendor/global.js  825 bytes          [emitted]         
           vendor/selenium-browserdetect.js    5.27 kB          [emitted]         
                                  prompt.js    7.25 kB          [emitted]         
                              highlight.css  952 bytes          [emitted]         
                          ../bootstrap.html    1.57 kB          [emitted]         
                           ../manifest.json    1.74 kB          [emitted]         
                               indicator.js  694 bytes          [emitted]         
                          ../indicator.html    1.03 kB          [emitted]         
                       ../icons/icon128.png    5.88 kB          [emitted]         
                   ../icons/icon_menu32.png    1.22 kB          [emitted]         
                        ../icons/icon16.png  612 bytes          [emitted]         
                   ../icons/icon_menu16.png  552 bytes          [emitted]         
                   ../icons/icon_menu64.png    2.76 kB          [emitted]         
                        ../icons/icon32.png    1.29 kB          [emitted]         
                        ../icons/icon64.png    2.91 kB          [emitted]         
                              ../index.html  315 bytes          [emitted]         
 [133] ./content/commands-api.js 6.84 kB {0} [built]
 [146] ./content/escape.js 5.11 kB {0} {6} [built]
 [229] ./content/locatorBuilders.js 11.6 kB {3} [built]
 [320] multi ./content/setup 28 bytes {5} [built]
 [321] ./content/setup.js 1.28 kB {5} [built]
 [322] multi ./content/commands-api 28 bytes {0} [built]
 [385] multi ./background/background 28 bytes {4} [built]
 [386] ./background/background.js 5.09 kB {4} [built]
 [387] multi ./content/record 28 bytes {1} [built]
 [388] ./content/record.js 19.5 kB {1} [built]
 [389] ./content/record-api.js 9.7 kB {1} [built]
 [390] ./content/prompt-recorder.js 2.41 kB {1} [built]
 [391] multi ./content/escape 28 bytes {6} [built]
 [392] multi react-hot-loader/patch ./neo/containers/Root 40 bytes {2} [built]
 [396] ./neo/containers/Root/index.jsx 1.61 kB {2} [built]
    + 1075 hidden modules
Child html-webpack-plugin for "../index.html":
     1 asset
       [0] ../node_modules/html-webpack-plugin/lib/loader.js!./neo/index.html 720 bytes {0} [built]
        + 3 hidden modules
lerna success run Ran npm script 'build' in 4 packages:
lerna success - browser-webdriver
lerna success - selenium-ide-extension
lerna success - selenium-side-runner
lerna success - selianize
✨  Done in 130.43s.

$ npm start

> selenium-ide@ start /Users/jack/ui/selenium-ide
> cd packages/selenium-ide && yarn start

yarn run v1.13.0-20181121.1436
$ env NODE_ENV=test webpack-dev-server --hot
Project is running at http://localhost:8081/
webpack output is served from /assets/
Hash: a6db07ced022ebcba304
Version: webpack 3.12.0
Time: 43408ms
                                      Asset       Size  Chunks                    Chunk Names
                                  prompt.js    7.25 kB          [emitted]         
media/selenium_blue_white32@3x.84ab23d0.svg    3.62 kB          [emitted]         
            media/selenium-ide.9b39b00c.svg    21.8 kB          [emitted]         
                                playback.js     617 kB       0  [emitted]  [big]  playback
                                  record.js     298 kB       1  [emitted]  [big]  record
                                     neo.js    18.7 MB       2  [emitted]  [big]  neo
                                   atoms.js    5.16 MB       3  [emitted]  [big]  atoms
                              background.js     988 kB       4  [emitted]  [big]  background
                               polyfills.js     957 kB       5  [emitted]  [big]  polyfills
                                  escape.js     898 kB       6  [emitted]  [big]  escape
                              highlight.css  952 bytes          [emitted]         
                           vendor/global.js  825 bytes          [emitted]         
           vendor/selenium-browserdetect.js    5.27 kB          [emitted]         
            media/selenium-ide.461193c2.ttf    7.44 kB          [emitted]         
                          ../bootstrap.html    1.57 kB          [emitted]         
                          ../indicator.html    1.03 kB          [emitted]         
                               indicator.js  694 bytes          [emitted]         
                           ../manifest.json    1.74 kB          [emitted]         
                   ../icons/icon_menu64.png    2.76 kB          [emitted]         
                   ../icons/icon_menu32.png    1.22 kB          [emitted]         
                       ../icons/icon128.png    5.88 kB          [emitted]         
                   ../icons/icon_menu16.png  552 bytes          [emitted]         
                        ../icons/icon16.png  612 bytes          [emitted]         
                        ../icons/icon64.png    2.91 kB          [emitted]         
                        ../icons/icon32.png    1.29 kB          [emitted]         
                              ../index.html  315 bytes          [emitted]         
  [40] (webpack)-dev-server/client?http://localhost:8081 7.93 kB {2} {3} {4} {5} {6} [built]
  [41] (webpack)/hot/dev-server.js 1.61 kB {2} {3} {4} {5} {6} [built]
 [170] ./src/content/commands-api.js 7.77 kB {0} [built]
 [183] ./src/content/escape.js 5.96 kB {0} {6} [built]
 [432] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./content/setup 52 bytes {5} [built]
 [433] ./src/content/setup.js 1.36 kB {5} [built]
 [434] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./content/commands-api 52 bytes {0} [built]
 [497] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./background/background 52 bytes {4} [built]
 [498] ./src/background/background.js 6.57 kB {4} [built]
 [499] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./content/record 52 bytes {1} [built]
 [500] ./src/content/record.js 23.2 kB {1} [built]
 [503] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server ./content/escape 52 bytes {6} [built]
 [504] multi (webpack)-dev-server/client?http://localhost:8081 webpack/hot/dev-server react-hot-loader/patch ./neo/containers/Root 64 bytes {2} [built]
 [505] ./node_modules/react-hot-loader/patch.js 40 bytes {2} [built]
 [600] ./src/neo/containers/Root/index.jsx 1.82 kB {2} [built]
    + 1163 hidden modules
Child html-webpack-plugin for "../index.html":
     1 asset
       [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/neo/index.html 720 bytes {0} [built]
       [1] ./node_modules/html-webpack-plugin/node_modules/lodash/lodash.js 540 kB {0} [built]
       [2] (webpack)/buildin/global.js 509 bytes {0} [built]
       [3] (webpack)/buildin/module.js 517 bytes {0} [built]
webpack: Compiled successfully.



©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容