JSDoc 中文网

包含包文件

包文件包含对你的项目文档有用的信息,例如项目的名称和版本号。JSDoc 在生成文档时可以自动使用项目的 package.json 文件中的信息。例如,默认模板会在文档中显示项目的名称和版本号。

🌐 Package files contain information that can be useful for your project's documentation, such as the project's name and version number. JSDoc can automatically use information from your project's package.json file when it generates documentation. For example, the default template shows the project's name and version number in the documentation.

package.json 文件纳入你的文档有两种方法:

🌐 There are two ways to incorporate a package.json file into your documentation:

  1. 在你的 JavaScript 文件的源路径中,包括指向 package.json 文件的路径。JSDoc 将使用它在源路径中找到的第一个 package.json 文件。
  2. 使用 -P/--package 命令行选项运行 JSDoc,指定你的 package.json 文件路径。此选项在 JSDoc 3.3.0 及更高版本中可用。

-P/--package 命令行选项优先于你的源路径。如果你使用 -P/--package 命令行选项,JSDoc 将会忽略源路径中的任何 package.json 文件。

🌐 The -P/--package command-line option takes precedence over your source paths. If you use the -P/--package command-line option, JSDoc will ignore any package.json files in your source paths.

package.json 文件必须使用 npm 的包格式

🌐 The package.json file must use npm's package format.

示例

🌐 Examples

在你的源路径中包含一个包文件
jsdoc path/to/js path/to/package/package.json
使用 -P/--package 选项
jsdoc --package path/to/package/package-docs.json path/to/js