You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置documentationjs解析的目录包含与排除规则?含node_modules排除方法

How to Configure Include/Exclude Rules for documentation.js (Excluding node_modules & Custom Directories)

Great question! Configuring include/exclude rules for documentation.js is straightforward once you know where to set it up—let's break this down step by step, focusing on blocking node_modules and other directories you don't want parsed. All of this is handled via a configuration file, most commonly a .jsdoc file (though you have other options too).

1. Create or Edit Your Configuration File

First, create a .jsdoc file in your project root if you don't already have one. This is a JSON file that tells documentation.js exactly which files to process and which to ignore.

2. Define Include/Exclude Rules

Add a source section to your .jsdoc file to specify your rules. Here's a practical example tailored to exclude node_modules and other common non-source directories:

{
  "source": {
    // Define which files/directories to INCLUDE in documentation
    "include": [
      "src/**/*.js",
      "lib/**/*.js" // Add any other source directories you want documented
    ],
    // Define which files/directories to EXCLUDE
    "exclude": [
      "node_modules/**/*", // Critical: Excludes all files in node_modules
      "dist/**/*", // Exclude built output
      "tests/**/*", // Exclude test files
      "docs/**/*" // Exclude existing documentation files
    ]
  }
}

Key Notes on Glob Patterns:

  • Use **/* to match all files and subdirectories within a folder (e.g., node_modules/**/* catches everything inside node_modules).
  • Be specific with your include rules to avoid accidentally pulling in unwanted files—stick to your actual source code directories.

3. Alternative: Use package.json for Configuration

If you prefer to keep all project config in one place, you can add the same rules directly to your package.json under a documentation key:

{
  "name": "your-project",
  "version": "1.0.0",
  "documentation": {
    "source": {
      "include": ["src/**/*.js"],
      "exclude": ["node_modules/**/*", "dist/**/*"]
    }
  }
}

4. Run documentation.js with Your Config

When you generate documentation, documentation.js will automatically pick up your .jsdoc file or package.json config by default. If you're using a custom-named config file (e.g., docs-config.jsdoc), specify it with the -c flag:

# Use default config (.jsdoc or package.json)
documentation build -o docs

# Use a custom config file
documentation build -c ./docs-config.jsdoc -o docs

5. Verify Your Rules Are Working

To double-check that node_modules and other excluded directories aren't being parsed, run the lint command with your config—it will list all files that documentation.js intends to process:

documentation lint -c .jsdoc

If you see any files you don't want in the output, adjust your exclude rules and re-run the check.

内容的提问来源于stack exchange,提问作者kmiklas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:12:45