JavaScript 中的 Bower 和 npm 有什麼區別?


  npm

npm 通常用於管理 Node.js 模組,並執行巢狀依賴樹。它還適用於前端,並用於 Grunt、CoffeeScript 等開發工具。

如果不使用巢狀依賴項,則很難避免依賴項衝突。因此,使用 npm 已被證明是很有益處的。

在 Node 中新增的任何內容都以模組的形式構成。在將 NPM 用於瀏覽器端依賴項時,你的程式碼結構會像 Node 一樣。

以下是依賴結構

project root
[node_modules]
-> dependency P
-> dependency Q
[node_modules]
-> dependency P
-> dependency R
[node_modules]
-> dependency Q
[node_modules]
-> dependency P
-> dependency S

Bower 

Bower 要求使用扁平依賴項樹,並且用於前端。它對於前端包很有用。

它載入純舊 JavaScript 檔案,例如在 <head> 標記中新增 <script>…</script>。

它針對前端進行了最佳化,並使用了扁平依賴項樹,其中每個包只需要一個版本。這最終將頁面載入量減少到了最低。

注意:Bower 現已棄用。

以下是依賴結構

project root
[bower_components]
-> dependency P
-> dependency Q // wants P
-> dependency R // wants Q and R
-> dependency S

更新於: 2019 年 9 月 12 日

150 次瀏覽

Kickstart Your 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.