js开发文档生成工具jsdoc安装使用

1、全局安装jsdoc,需要先安装node环境哦~

npm install -g jsdoc

 

2、在项目根目录新建文件conf.json,内容如下:

{
    "tags": {
        "allowUnknownTags": true,
        // 指定所用词典
        "dictionaries": [
            "jsdoc"
        ]
    },
    // 查找文件的深度 需要用 -r 参数
    "recurseDepth": 10,
    "source": {
        "include": [
            // 需要编译的文件路径 使用时请替换
            "./src"
        ],
         // 需要编译的文件类型,根据需求设置
        "includePattern": ".+\\.(js||vue)$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    // 使用插件,不是必须,如果只编译js文档,可不设置,编译vue文件需要安装jsdoc-vue模块
    "plugins": [
        // 插件路径,编译vue文件需要使用jsdoc-vue插件
        "./jsdoc-vue"
    ],
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": true,
        "useLongnameInNav": false,
        "showInheritedInNav": true
    },
    "opts": {
        // 文档输出路径
        "destination": "./example",
        "encoding": "utf8",
        "private": true,
        "recurse": true,
        // 使用模板 minami,需要先下载npm install -d minami
        "template": "./node_modules/minami"
    }
}

 

3、编译命令,运行命令生成html文档,文档目录在conf.json里设置

jsdoc -c conf.json

把README.md文件设为主页(home)
jsdoc -c conf.json README.md

 

4、本地安装jsdoc-vue

npm install -d jsdoc-vue

 

5、项目根目录新建jsdoc-vue.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 : '';
    }
  }
};

 

6、jsdoc使用文档请查看:https://www.html.cn/doc/jsdoc/about-namepaths.html

结尾~

posted @ 2019-08-01 10:52  飞天狼  阅读(802)  评论(0编辑  收藏  举报