Gathering detailed insights and metrics for babel-plugin-transform-react-remove-prop-types
Gathering detailed insights and metrics for babel-plugin-transform-react-remove-prop-types
Gathering detailed insights and metrics for babel-plugin-transform-react-remove-prop-types
Gathering detailed insights and metrics for babel-plugin-transform-react-remove-prop-types
@vlad-zhukov/babel-plugin-transform-react-remove-prop-types
Remove unnecessary React propTypes from the production build
@stevoland/babel-plugin-transform-react-remove-prop-types
Remove unnecessary React propTypes from the production build
babel-plugin-transform-styled-components-remove-prop-types
Remove unnecessary React propTypes from styled-components
@hishprorg/dolore-nam
## Note this is a fork of jsinspect that now supports ES2020 standard (and most proposed features), TS and TSX files. It uses Babel 8's parser, upgrading from babylon to the new babel/parser. Support for Flow has been removed in favour of TS.
Remove unnecessary React propTypes from the production build. 🎈
npm install babel-plugin-transform-react-remove-prop-types
Typescript
Module System
Node Version
NPM Version
99.2
Supply Chain
99.1
Quality
78.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,208,637,218
Last Day
788,403
Last Week
3,608,717
Last Month
16,690,384
Last Year
225,380,501
895 Stars
254 Commits
61 Forks
15 Watching
4 Branches
27 Contributors
Minified
Minified + Gzipped
Latest Version
0.4.24
Package Id
babel-plugin-transform-react-remove-prop-types@0.4.24
Size
10.80 kB
NPM Version
6.1.0
Node Version
8.9.1
Publised On
01 Feb 2019
Cumulative downloads
Total Downloads
Last day
-5.9%
788,403
Compared to previous day
Last week
-18.7%
3,608,717
Compared to previous week
Last month
6.9%
16,690,384
Compared to previous month
Last year
-9.8%
225,380,501
Compared to previous year
26
Remove unnecessary React propTypes from the production build.
1npm install --save-dev babel-plugin-transform-react-remove-prop-types
Remove React propTypes
from the production build, as they are only used in development.
You can save bandwidth by removing them.
In
1const Baz = (props) => ( 2 <div {...props} /> 3); 4 5Baz.propTypes = { 6 className: PropTypes.string 7};
Out
1const Baz = (props) => ( 2 <div {...props} /> 3);
The majority of cases should be addressed by default by this plugin.
In some cases, for example when using HOCs (High Order Components), like react-redux's connect
, or component inheritance (although it's NOT recommended), a comment after the propTypes
definition may be used to force the removal:
1Component.propTypes /* remove-proptypes */ = {}
.babelrc
(Recommended).babelrc
without options:
1{ 2 "env": { 3 "production": { 4 "plugins": ["transform-react-remove-prop-types"] 5 } 6 } 7}
with options:
1{ 2 "env": { 3 "production": { 4 "plugins": [ 5 ["transform-react-remove-prop-types", { 6 "mode": "wrap", 7 "ignoreFilenames": ["node_modules"] 8 }] 9 ] 10 } 11 } 12}
1babel --plugins transform-react-remove-prop-types script.js
without options:
1require('babel-core').transform('code', { 2 plugins: [ 3 'transform-react-remove-prop-types', 4 ], 5});
with options:
1require('babel-core').transform('code', { 2 plugins: [ 3 [ 4 'transform-react-remove-prop-types', 5 { 6 mode: 'wrap', 7 ignoreFilenames: ['node_modules'], 8 }, 9 ], 10 ], 11});
mode
remove
(default):
the propTypes
definitions are removed from the source code.wrap
:
the propTypes
definitions are wrapped with the following code:1Component.propTypes = process.env.NODE_ENV !== "production" ? { 2 // ... 3} : {};
Accessing Component.propTypes.className
won't throw. It's a tradeoff between the size of the output file and the likelihood libraries like react-native-hyperlink breaks.
unsafe-wrap
:
the propTypes
definitions are wrapped with the following code:1if (process.env.NODE_ENV !== "production") { 2 Component.propTypes = { 3 // ... 4 } 5}
Accessing Component.propTypes.className
will throw.
The wrap modes are targeting React libraries like material-ui or react-native-web. They are not intended to be used by application authors.
removeImport
true
: the import statements are removed as well. This option only works if mode
is set to remove
:1import PropTypes from 'prop-types'
false
(default): does not remove the import statements.ignoreFilenames
This filter generates a regular expression. Any filenames containing one of the array's strings will be ignored. By default, we match everything.
Following the Is it safe? section, you might encounter a component
depending on the propTypes
at runtime to work.
For this reason, we provide an array options to filter out some files and folders.
For instance, you can ignore all the npm modules:
1ignoreFilenames: ['node_modules'],
additionalLibraries
This option gives the possibility to remove other propTypes
in addition to the canonical prop-types
.
For instance, by default
1import PropTypes from 'prop-types' 2import ImmutablePropTypes from 'react-immutable-proptypes'
will result in the latter not to be removed, while with:
1additionalLibraries: ['react-immutable-proptypes'],
both will be removed.
If you are using Babel 7 or newer and your config is stored in babel.config.js
, you can also use a regular expression to describe modules, which should be removed.
This would be particularly useful when using custom prop types validators, implemented as part of your own source code. For example
1import CustomPropTypes from '../../prop-types/my-own-validator' 2import OtherCustomPropTypes from '../../prop-types/my-other-validator'
would be removed with the following setting
1additionalLibraries: [/\/prop-types\/.*$/]
If you use an index file
1import CustomPropTypes from '../../prop-types'
you could set it up as
1additionalLibraries: [/\/prop-types$/]
classNameMatchers
Use this option to enable this plugin to run on components that extend a class different than React.Component
or React.PureComponent
.
Given this example:
1class MyComponent extends BaseComponent { 2 ... 3}
You would use:
1classNameMatchers: ["BaseComponent"]
createReactClassName
Use this option to set a custom name for the import of the create-react-class
package that is different than createReactClass
.
Given this example:
1import createClass from 'create-react-class';
You would use:
1createReactClassName: 'createClass'
If you are using the propTypes
in a conventional way,
i.e by using them to perform type checking on the properties, that plugin should be safe to use.
However, some libraries are accessing the propTypes
on the component directly.
For instance react-native-vector-icons use them to split the properties between two components:
1const touchableProps = pick(restProps, Object.keys(TouchableHighlight.propTypes));
:warning: The plugin is breaking that code if it ends up removing TouchableHighlight.propTypes
.
Make sure you are:
propTypes
to work around that limitation.node_modules
.
If you do, test that your code is still working before shipping into production.eslint-plugin-react has a rule forbid-foreign-prop-types that can help you make this plugin safer to use.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 12/28 approved changesets -- score normalized to 4
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
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
39 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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