Remove unnecessary React propTypes from the production build.
npm install --save-dev babel-plugin-transform-react-remove-prop-types
Remove unnecessary React propTypes
from the production build.
You can save bandwidth by removing them.
In
const Baz = () => (
<div />
);
Baz.propTypes = {
foo: React.PropTypes.string
};
Out
const Baz = () => (
<div />
);
.babelrc
without options:
{
"env": {
"production": {
"plugins": ["transform-react-remove-prop-types"]
}
}
}
with options:
{
"env": {
"production": {
"plugins": [["transform-react-remove-prop-types", {"mode": "wrap"}]]
}
}
}
babel --plugins transform-react-remove-prop-types script.js
without options:
require('babel-core').transform('code', {
plugins: [
'transform-react-remove-prop-types',
],
});
with options:
require('babel-core').transform('code', {
plugins: [
[
'transform-react-remove-prop-types',
{mode: 'wrap'},
],
],
});
remove
(default): thepropTypes
definitions are removed from the source code.wrap
: thepropTypes
definitions are wrapped with the following code:
if (process.env.NODE_ENV !== "production") {
// ...
}
The wrap
mode is targeting react libraries like material-ui.
It's not intended to be used in userland.
MIT