npm-ls

列出已安装的包

概要

npm ls [[<@scope>/]<pkg> ...]

aliases: list, la, ll

描述

这个命令将打印出所有安装的包的版本,以及它们的依赖关系,会以树形结构方式显示。树的显示是依赖包逻辑关系,而不是node_modules文件夹的物理布局。

以下例子以此为前提条件:

  • 在D盘有testnpm目录
  • 目录中有package.json文件和node_modules目录
  • package.json的name值testnpm
  • node_modules中有jquery和swiper安装包及其依赖包dom7
  • jquery属于dependencies,swiper属于devDependencies
  • 通过npm init,npm i jquery,npm i swiper --save-dev等操作实现
    > npm ls
    [email protected] D D:\testnpm
    +-- [email protected]
    `-- [email protected]
    `-- [email protected]
    

当以ll或la运行时,还显示扩展信息。

> npm ll

[email protected]
| D:\testnpm
|
+-- [email protected]
|   JavaScript library for DOM operations
|   git+https://github.com/jquery/jquery.git
|   https://jquery.com
`-- [email protected]
  | Most modern mobile touch slider and framework with hardware accelerated transitions
  | git+https://github.com/nolimits4web/Swiper.git
  | http://www.idangero.us/swiper/
  `-- [email protected]
      Minimalistic JavaScript library for DOM manipulation, with a jQuery-compatible API
      git+https://github.com/nolimits4web/Dom7.git
      http://framework7.io/docs/dom.html

配置

json
  • 默认:false
  • 类型:Boolean

以JSON格式显示信息。

# 仅列出jquery
> npm ls --json
{
  "dependencies": {
    "jquery": {
      "version": "3.2.1",
      "from": "jquery@x",
      "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.2.1.tgz"
    }
  }
}
long
  • 默认:false
  • 类型:Boolean

显示扩展的信息。

# 仅列出jquery
$ npm ls --long
[email protected]
| D:\testnpm
|
`-- [email protected]
    JavaScript library for DOM operations
    git+https://github.com/jquery/jquery.git
    https://jquery.com
parseable
  • 默认:false
  • 类型:Boolean

展示所有安装的包的绝对路径。

> npm ls --parseable
D:\testnpm
D:\testnpm\node_modules\jquery
D:\testnpm\node_modules\swiper
D:\testnpm\node_modules\dom7
global
  • 默认:false
  • 类型:Boolean

列出全局安装包,而不是当前目录中的安装包。

> npm ls --global
depth
  • 类型:int

依赖关系树的最大显示深度。

> npm ls --depth=1
[email protected] D:\testnpm
+-- [email protected]
`-- [email protected]
  `-- [email protected]
prod / production
  • 类型:Boolean
  • 默认:false

仅显示添加到dependencies中的安装包。

> npm ls --prod
[email protected] D:\testnpm
`-- [email protected]
dev
  • 类型:Boolean
  • 默认:false

仅显示添加到devDependencies中的安装包。

> npm ls --dev
[email protected] D:\testnpm
`-- [email protected]
  `-- [email protected]
only
  • 类型:String 当only为dev或development,同上dev 当only为prod或production,同上prod
> npm ls --only="dev"
[email protected] D:\testnpm
`-- [email protected]
  `-- [email protected]

-- 类型:Boolean -- 默认:false

仅显示链接的安装包。

> npm ls --link

results matching ""

    No results matching ""