Gathering detailed insights and metrics for babel-plugin-react-docgen
Gathering detailed insights and metrics for babel-plugin-react-docgen
Gathering detailed insights and metrics for babel-plugin-react-docgen
Gathering detailed insights and metrics for babel-plugin-react-docgen
📝 Babel plugin to add react-docgen info into your code.
npm install babel-plugin-react-docgen
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
162 Stars
225 Commits
67 Forks
56 Watching
6 Branches
115 Contributors
Updated on 10 Mar 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-10.1%
244,773
Compared to previous day
Last week
4.6%
1,393,750
Compared to previous week
Last month
8%
5,794,565
Compared to previous month
Last year
-47.9%
88,647,032
Compared to previous year
react-docgen allows you to write propType descriptions, class descriptions and access propType metadata programatically.
This babel plugin allow you to access those information right inside your React class.
For an example, let's say you've a React class like this:
1/** 2 This is an awesome looking button for React. 3*/ 4import React from 'react'; 5 6export default class Button extends React.Component { 7 render() { 8 const { label, onClick } = this.props; 9 return ( 10 <button onClick={onClick}>{ label }</button> 11 ); 12 } 13} 14 15Button.propTypes = { 16 /** 17 Label for the button. 18 */ 19 label: React.PropTypes.string, 20 21 /** 22 Triggered when clicked on the button. 23 */ 24 onClick: React.PropTypes.func, 25};
With this babel plugin, you can access all these information right inside your app with:
1console.log(Button.__docgenInfo);
1{ 2 description: 'This is an awesome looking button for React.', 3 props: { 4 label: { 5 type: { 6 name: 'string' 7 }, 8 required: false, 9 description: 'Label for the button.' 10 }, 11 onClick: { 12 type: { 13 name: 'func' 14 }, 15 required: false, 16 description: 'Triggered when clicked on the button.' 17 } 18 } 19}
This will be pretty useful for documentations and some other React devtools like Storybook.
Install the plugin:
1npm install -D babel-plugin-react-docgen
Use it inside your .babelrc
1{ 2 "plugins": ["react-docgen"] 3}
option | description | default |
---|---|---|
resolver | You may use the 3 built-in react-docgen resolvers by specifying its name as a string , or you may specify a custom resolver by specifying the function explicitly. | "findAllExportedComponentDefinition" |
handlers | All react-docgen handlers are automatically applied. However, custom handlers can be added by specifying them here. Any string value will be loaded by require , and a function will be used directly. | |
removeMethods | Used to remove docgen information about methods. | false |
DOC_GEN_COLLECTION_NAME | The name of a global variable where all docgen information can be stored. See below for more information. | |
...options | Remaining options will be passed directly as react-docgen options. Any options they allowed will be passed through, but the filename will be overwritten by the filename provided by babel. |
Sometimes, it's a pretty good idea to collect all of the docgen info into a collection. Then you could use that to render style guide or similar.
So, we allow you to collect all the docgen info into a global collection. To do that, add following config to when loading this babel plugin:
1{ 2 "plugins":[ 3 [ 4 "babel-plugin-react-docgen", 5 { 6 "DOC_GEN_COLLECTION_NAME": "MY_REACT_DOCS", 7 "resolver": "findAllComponentDefinitions", // optional (default: findAllExportedComponentDefinitions) 8 "removeMethods": true, // optional (default: false) 9 "handlers": ["react-docgen-deprecation-handler"] // optional array of custom handlers 10 } 11 ] 12 ] 13}
Then you need to create a global variable(an object) in your app called MY_REACT_DOCS
before any code get's executed.
Then we'll save them into that object. We do it by adding a code block like this to the transpiled file:
1if (typeof MY_REACT_DOCS !== 'undefined') { 2 MY_REACT_DOCS['test/fixtures/case4/actual.js'] = { 3 name: 'Button', 4 docgenInfo: Button.__docgenInfo, 5 path: 'path/to/my/button.js' 6 }; 7}
We parse your code with react-docgen
to get this info, but we only do it for files which contain a React component.
There will be some overhead to your project, but you can leverage babel's cache directory to avoid this a huge performance hit.
Yes this increase the output size of your transpiled files. The size increase varies depending on various factors like:
Most of the time, you need this plugin when you are developing your app or with another tool like Storybook. So, you may not need to use this on the production version of your app.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/3 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
19 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More