The `babel-plugin-react-docgen` package is a Babel plugin designed to embed documentation metadata, generated by `react-docgen`, directly into React component definitions during the build process. Instead of requiring a separate build step or runtime parsing, this plugin augments your React components with a `__docgenInfo` static property, making propType descriptions, component descriptions, and other metadata programmatically accessible at runtime. This capability is highly beneficial for tools such as Storybook, style guides, or developer tools that consume component metadata. The current stable version is 4.2.1. The project appears to have an infrequent release cadence, with major versions released every few years, often in response to updates in `react-docgen` or the Babel ecosystem itself. Its key differentiator is the seamless integration of docgen output directly into the component's generated code, simplifying access to documentation metadata.
npm install babel-plugin-react-docgenVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic installation and configuration of the plugin in `babel.config.js`, along with an example React component showing how `__docgenInfo` is generated.
Upgrade `@babel/core`, `@babel/cli`, and other Babel presets/plugins to their Babel 7 compatible versions. Adjust `.babelrc` or `babel.config.js` syntax as per Babel 7 migration guides.
Consult the `react-docgen` v6 changelog for specific API changes related to resolvers and handlers. Update any custom implementations to conform to the new `react-docgen` API.
Ensure the specified global variable is an initialized object in your application's entry point or setup script before any React components are loaded.
Refactor components to import `PropTypes` from the `prop-types` package and use it (e.g., `import PropTypes from 'prop-types'; MyComponent.propTypes = { ... };`).Verify that `babel-plugin-react-docgen` is correctly listed in your `babel.config.js` or `.babelrc` and that the file containing the component is being transpiled by Babel.
Before any components processed by the plugin are executed, ensure the global variable is initialized as an empty object (e.g., `window.MY_GLOBAL_DOCS = {};` in browsers or `global.MY_GLOBAL_DOCS = {};` in Node.js).Ensure the path to your custom resolver is correct and that it can be resolved by Node.js's module resolution system. Alternatively, provide the resolver function directly rather than its string name.
No dependency data recorded yet.