React Docgen TypeScript Webpack Plugin
raw JSON →This Webpack plugin is designed to generate documentation generation (docgen) information specifically for TypeScript React components. It integrates with your Webpack configuration to parse component props and JSDoc comments, primarily intended for use with tools like Storybook's `addon-info` (though `addon-info` itself is now deprecated). The current stable version is 1.1.0. However, the project explicitly states it's experimental, a 'hack job,' and 'not suitable for production.' It has not seen updates since 2019, indicating an abandoned release cadence. Its key differentiator was providing TypeScript support for React docgen at a time when this was less common, but due to its unmaintained status and limitations, it's not recommended for new projects.
Common errors
error Docgen information not appearing for my TypeScript React component in Storybook's addon-info. ↓
export const MyComponent) and that your Storybook story's title exactly matches this named export. error Webpack build error or unexpected behavior when using TypeScript with `module: esnext` and react-docgen-typescript-webpack-plugin. ↓
tsconfig.json to use a different module target like commonjs or es2015 if possible, and re-evaluate your build. Warnings
breaking This plugin is marked as 'Experimental' and 'not suitable for production' by its maintainers. It has not been updated since 2019, indicating it is likely abandoned. Use with caution or consider modern alternatives. ↓
gotcha Docgen information cannot be generated for components exported only as `default`. Components must be exported using a named export to be processed correctly. ↓
gotcha The plugin may have issues when the TypeScript compiler option `module` is set to `esnext`. ↓
gotcha When used with Storybook's `addon-info` (which is now deprecated), the Storybook story name must exactly match the component's name for docgen information to be read. ↓
Install
npm install react-docgen-typescript-webpack-plugin yarn add react-docgen-typescript-webpack-plugin pnpm add react-docgen-typescript-webpack-plugin Imports
- TSDocgenPlugin wrong
const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin').TSDocgenPlugin;correctimport TSDocgenPlugin from 'react-docgen-typescript-webpack-plugin';
Quickstart
const path = require('path');
const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin');
// Assuming a Storybook context, this generates the default Webpack config
// This path might need adjustment based on your Storybook version
const genDefaultConfig = require('@storybook/react/dist/server/config/defaults/webpack.config.js');
module.exports = (baseConfig, env) => {
const config = genDefaultConfig(baseConfig);
config.module.rules.push({
test: /\.tsx?$/,
include: path.resolve(__dirname, '../src'), // Adjust to your components directory
loader: require.resolve('ts-loader'),
});
config.plugins.push(new TSDocgenPlugin());
config.resolve.extensions.push('.ts', '.tsx');
return config;
};