跳到主要內容

dotnet core libman 安裝及操作

libman 是 dotnet core 常用的CLI 整合工具,其一般安裝方式可以透過dotnet sdk 命令進行執行

dotnet tool install -g Microsoft.Web.LibraryManager.Cli 

完成安裝後,使用者資料夾\.dotnet\tools\.store 會看到 microsoft.web.librarymanager.cli



可以在主控台環境下執行libman 相關指令 libman --help 或 libman -h

查詢libman 版本

libman --version



在網站專案使用 LibMan 做套件管理  libman init



使用「ibman init」 進行初始化之後,專案資料夾會建立 「libman.json」 檔案,若沒有選擇特定提供者,則會以 cdnjs 為主要來源做預設值(直接按 Enter就會以 cdnjs),其它有效選項為
cdnjs、filesystem、jsdelivr、unpkg


{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": []
}

這裡有一點需要注意,就是進行 libman init 初始化後,如果專案在vs code 的環境之下執行,必須重新再開啟專案喔

接下來這裡使用 libman 安裝 jquery3.5.1  為範例


Windows PowerShell
Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。

請嘗試新的跨平台 PowerShell https://aka.ms/pscore6

PS E:\janchen\AspNetCore1\AspNetCore1> libman install jquery@3.5.1 --provider cdnjs --destination wwwroot\scripts\jquery

正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js...
正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js...      
正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.map...     
正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.js...     
正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js... 
正在下載檔案 https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.map...
wwwroot/scripts/jquery/jquery.js 已寫入磁碟
wwwroot/scripts/jquery/jquery.min.js 已寫入磁碟
wwwroot/scripts/jquery/jquery.min.map 已寫入磁碟     
wwwroot/scripts/jquery/jquery.slim.js 已寫入磁碟     
wwwroot/scripts/jquery/jquery.slim.min.js 已寫入磁碟 
wwwroot/scripts/jquery/jquery.slim.min.map 已寫入磁碟
已將程式庫 "jquery@3.5.1" 安裝到 "wwwroot\scripts\jquery"
PS E:\janchen\AspNetCore1\AspNetCore1> 


jqery3.5.1  會透過 LibMan 安裝至專案的 wwwroot/scripts/jquery資料夾,若只須安裝 jquery.min.js,則可以再以下列指令進行安裝

libman install jquery@3.5.1 --provider cdnjs --destination wwwroot\scripts\jquery --files jquery.min.js




執行安裝後,libman.json 也會紀錄安裝的前端程式庫資訊

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "jquery@3.5.1",
      "destination": "wwwroot\\scripts\\jquery"
    }
  ]
}


若其他專案需要相同的程式庫配置方式,也可以透過 libman restore ,將 libman.json 的相關程式進行還原安裝


相關參考:



以上就是LibMan 的使用操作














留言