Appearance
此项目为前端项目编写jsDoc格式注解,再编译后可以生成详细文档。
安装环境
bash
npm install jsdoc@3.5.5 tui-jsdoc-template@1.2.2 --save-dev
配置环境
- 根目录配置Vue模板解析文件
jsdoc-vue.js
js
var compiler = require('vue-template-compiler');
exports.handlers = {
// 利用 vue-template-compiler 编译 vue 模板
beforeParse: function (e) {
if (/\.vue$/.test(e.filename)) {
var output = compiler.parseComponent(e.source);
e.source = output.script ? output.script.content : '';
}
}
};
- 根目录配置jsdoc配置文件
docjs.conf.js
js
module.exports = {
"tags": {
"allowUnknownTags": true,
// 指定所用词典
"dictionaries": [
"jsdoc"
]
},
// 查找文件的深度 需要用 -r 参数
"recurseDepth": 10,
"source": {
"include": [
// 需要编译的文件路径 使用时请替换
"./src"
],
"includePattern": ".+\\.(vue|js)$",
"excludePattern": "(^|\\/|\\\\)_"
},
// 使用插件
"plugins": [
// 插件路径
"./jsdoc-vue"
],
"templates": {
"cleverLinks": false,
"monospaceLinks": true,
"useLongnameInNav": false,
"showInheritedInNav": true
},
"opts": {
// 文档输出路径
"destination": "./jsdoc",
"encoding": "utf8",
"private": true,
"recurse": true,
// 使用模板 minami
"template": "./node_modules/tui-jsdoc-template"
}
}
配置执行命令
json
"generate-docs": "node_modules/.bin/jsdoc --configure docjs.conf.js --verbose"
例子