將 Lodash 新增到 CLI 應用程式

一個常用的實用程式庫是 Lodash 。要首先將其安裝到 Aurelia CLI 驅動的應用程式中,你需要使用 Npm 進行安裝。

npm install lodash --save

現在,在你首選的 IDE /程式碼編輯器中,開啟專案目錄中的以下檔案:aurelia_project / aurelia.json,然後向下滾動到檔案末尾的 build.bundles 部分。我們想要將 Lodash 新增到其中一個包中。對於此示例,我們將 Lodash 新增到供應商包中。

因為 Lodash 確實遵循 CommonJS 約定並匯出一個連線檔案,所以我們可以通過新增以下物件或者依賴項陣列來輕鬆註冊它:

{
  "name": "lodash",
  "path": "../node_modules/lodash/lodash.min"
}

請注意,我們省略了 .js 檔案字尾,因為在解析依賴項時會自動附加這些字尾。

現在我們可以使用 ES6 匯入語法簡單地匯入 Lodash:

import _ from 'lodash';