命令
npm home 命令用于快速打开指定 npm 包的官网。例如,npm home react 会尝试打开 React 库的官方网站。
- npm home PACKAGE_NAME 该命令会首先查找指定包的 package.json 文件中的 homepage 字段,如果存在,则打开该字段指定的网址。
json
{
"name": "react",
"description": "React is a JavaScript library for building user interfaces.",
"keywords": [
"react"
],
"version": "19.1.0",
"homepage": "https://react.dev/",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react.git",
"directory": "packages/react"
},
}
- 如果 homepage 字段不存在,npm 会继续寻找 repository 字段,然后打开项目在代码仓库(如 GitHub)中的托管地址,并拼接 #readme 路径。
-
例如,如果一个包的 repository 字段指定的是 https://github.com/example/user,那么 npm home 命令将会打开 https://github.com/example/user#readme。
js// npm home mineflayer -> https://github.com/PrismarineJS/mineflayer#readme "repository": { "type": "git", "url": "git://github.com/PrismarineJS/mineflayer.git" }
-
如果想要打开其他包的官网,只需将 PACKAGE_NAME 替换为相应的包名即可。例如,npm home lodash 会打开 Lodash 包的官网。