For faster navigation, this Iframe is preloading the Wikiwand page for Yarn.

Yarn

Yarn
開發者Meta Platforms
首次发布2016年6月18日,​8年前​(2016-06-18[1]
当前版本
  • 4.4.1 (2024年8月24日;穩定版本)[2]
編輯維基數據鏈接
源代码库https://github.com/yarnpkg
编程语言JavaScript
平台跨平臺
类型套件管理器
许可协议
  • 2句版BSD许可证
編輯維基數據鏈接
网站yarnpkg.com

Yarn 是其中一種主要的 JavaScript 套件管理器,[3][4] 由 Meta(前身為 Facebook)於 2016 年應對 Node.js JavaScript 平臺執行環境所開發。 作為 NPM 套件管理器的替代方案,Yarn 是由 Facebook、Exponent(現在為 Expo.dev)、谷歌和 Tilde(Ember.js 背後的公司)協力開發,主要是用於解決大型基準原始程式碼的一致性、安全性和性能問題。[5]

功能

[编辑]

使用者可以撰寫Yarn平臺的外掛。

約束程式碼(constraints)

[编辑]

Yarn 約束程式碼可以讓用戶在工作空間範圍內中為其相依套件或清單字段強制規定執行規則。

離線快取(Offline cache)

[编辑]

下載的套件能被以單一檔案的方式快取或儲存。

隨插即用(Plug'n'Play)

[编辑]

隨插即用(Plug'n'Play)能讓用戶在沒有 node_modules資料夾的情況下執行 Node 專案,定義了使用 隨插即用控制(Plug-n-Play-control)檔案分析相依性套件檔案的方式或位置。此功能專門在修復結構不良的 node_modules架構,從而加快 Node.js 應用程式的啟動時間。

外掛(Plugins)

[编辑]

外掛(Plugins)可以添加新的解析器(resolvers)、接收器(fetchers)、連結器(linkers)、指令(commands),也可以註冊一些事件或者互相整合,Yarn的大部分功能都是通過外掛實作的,包括yarn addyarn install,也是預先安裝好的外掛。

協定(Protocols)

[编辑]

用戶可以定義將使用哪種協定來解析某些套件,例如,git 協定是用於從 Git 存儲庫下載公用套件,patch 協定用於建立原始套件的修正副本。

發布流程(Release Workflow)

[编辑]

發布流程(Release Workflow) 會在原始套件(root package)完成升級之後,自動升級單一儲存庫工作區之間的相關套件。

工作區(Workspaces)

[编辑]

工作區(Workspaces)可以讓多個專案在同一個存儲庫中一起進行工作,並在修改原始程式碼時自動套用修改到其他相關專案,使其可以通過只有執行一次安裝命令來一次安裝多個套件。

與NPM的比較

[编辑]
  • Yarn 可以從本機暫存區安裝套件。[6]
  • Yarn 強烈綁定套件的版本。
  • Yarn 使用校驗(checksum)和來確保資料完整性,對比 NPM 使用 SHA-512 來檢查下載套件的資料完整性。[7]
  • Yarn 以平行的方式安裝套件,對比 NPM 以一次性的方式安裝一個套件。

語法

[编辑]

安裝Yarn:

npm install -g yarn

注意:npm安裝預設為"yarn classic",即第一個版本;如需安裝最新版,則須再額外執行下列步驟:[1]页面存档备份,存于互联网档案馆

corepack enable
yarn set version stable

利用Yarn安裝套件[8]

yarn add [package-name]

或是將套件加入"devDependencies"

yarn add -D [package-name]

注意:在第一個版本中是這樣安裝:

yarn install [package-name] --save-dev

參見

[编辑]

參考文獻

[编辑]
  1. ^ Earliest releases of yarn. GitHub. [Jun 18, 2016]. (原始内容存档于2023-02-27). 
  2. ^ Release 4.4.1. 2024年8月24日 [2024年8月27日]. 
  3. ^ Package management basics. MDN. 2022-09-28 [2023-04-10]. (原始内容存档于2023-05-21). 
  4. ^ 5 best JavaScript Package Managers. Dunebook.com. 2022-02-05 [2023-04-10]. (原始内容存档于2023-04-21). 
  5. ^ Yarn: A new package manager for JavaScript. Engineering at Meta. 2016-10-11 [2021-11-22]. (原始内容存档于2023-06-15) (美国英语). 
  6. ^ Package Manager – NPM and Yarn Explained with Examples. Sitepoint. 2021-09-21 [2023-04-10]. (原始内容存档于2023-05-17). 
  7. ^ How To Install and Use the Yarn Package Manager for Node.js. DigitalOcean. 2021-08-10 [2023-04-10]. (原始内容存档于2023-03-26). 
  8. ^ Yarn vs npm: Everything You Need to Know. CodeSweetly. 2023-02-04 [2023-04-10]. (原始内容存档于2023-05-19). 
{{bottomLinkPreText}} {{bottomLinkText}}
Yarn
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?