Webpack Loader for TypeScript React Component Docgen

3.7.2 · active · verified Sun Apr 19

react-docgen-typescript-loader is a Webpack loader designed to extract documentation (docgen) information from TypeScript React components. This information, including component prop types, descriptions, and default values, is primarily utilized to populate dynamic documentation tables, especially within tools like Storybook's Info Addon or Docs Addon. The current stable version is 3.7.2. While there's no fixed release cadence, updates typically align with major changes in React, TypeScript, or Webpack. Its key differentiator is its specific focus on TypeScript components, offering robust type introspection to enrich component documentation automatically, reducing manual documentation effort for developers working in TypeScript-heavy React ecosystems.

Common errors

Warnings

Install

Imports

Quickstart

This configuration demonstrates how to integrate `react-docgen-typescript-loader` into a Storybook Webpack setup, ensuring it processes `.tsx` and `.ts` files after `ts-loader` to generate prop type documentation for components.

const path = require("path");

module.exports = (baseConfig, env, config) => {
  config.module.rules.push({
    test: /\.tsx?$/,
    include: path.resolve(__dirname, "../src"),
    use: [
      require.resolve("ts-loader"),
      {
        loader: require.resolve("react-docgen-typescript-loader"),
        options: {
          // Optional: specify a tsconfig.json file for better type resolution
          // tsconfigPath: path.resolve(__dirname, '../tsconfig.json'),
          // Optional: exclude files from being processed
          // exclude: ['node_modules'],
          // Optional: include files from being processed
          // include: ['src'],
        }
      }
    ]
  });

  // Required for Storybook to resolve .tsx files
  config.resolve.extensions.push('.ts', '.tsx');

  return config;
};

view raw JSON →