typedoc seems to be including all the files from tsconfig.json “includes” property. Is this correct? I would like to include only code from my “src” directory regardless of what tsconfig.json “includes” contains. Is this possible in typedoc?

Yes, you can configure TypeDoc to include only files from your “src” directory, even if your tsconfig.json file has a broader “includes” property. Here are the primary methods to achieve this:

1. Using the --exclude option:

  • When running TypeDoc from the command line, pass the --exclude option multiple times to specify the directories you want to exclude:

    Bash
    typedoc --exclude "**/node_modules/**" --exclude "**/tests/**" --out docs src
    
    • This command will generate documentation from files in the “src” directory, while excluding files in “node_modules” and “tests” directories.

2. Using a configuration file:

  • Create a TypeDoc configuration file (e.g., typedoc.json or typedoc.js) with the following options:

    JSON
    {
      "exclude": [
        "**/node_modules/**",
        "**/tests/**"
      ],
      "entryPoints": ["./src"]
    }
    
  • Then, run TypeDoc without explicitly specifying input files:

    Bash
    typedoc --out docs
    

3. Contextualizing with tsconfigReferences (for complex projects):

  • If your project involves multiple tsconfig.json files, set the tsconfigReferences option in your TypeDoc configuration file to ensure correct context for file inclusion:

    JSON
    {
      "exclude": [
        "**/node_modules/**",
        "**/tests/**"
      ],
      "entryPoints": ["./src"],
      "tsconfig": ["./tsconfig.json"],
      "tsconfigReferences": true
    }
    

Remember:

  • Place the configuration file in the root of your project or a directory named .config.
  • Adjust exclude patterns and entry points based on your specific project structure.

By following these methods, you can effectively control which files are included in your TypeDoc-generated documentation, ensuring it focuses solely on your desired source code.

Leave a Reply

Your email address will not be published. Required fields are marked *