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 文件。

    ¥In the source paths to your JavaScript files, include the path to a package.json file. JSDoc will use the first package.json file that it finds in your source paths.

  2. 使用 -P/--package 命令行选项运行 JSDoc,指定 package.json 文件的路径。此选项在 JSDoc 3.3.0 及更高版本中可用。

    ¥Run JSDoc with the -P/--package command-line option, specifying the path to your package.json file. This option is available in JSDoc 3.3.0 and later.

-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