Package Exports
- babel-plugin-transform-react-remove-prop-types
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-react-remove-prop-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
babel-plugin-transform-react-remove-prop-types
Remove unnecessary React propTypes from the production build.
Installation
npm install --save-dev babel-plugin-transform-react-remove-prop-types
The problem solved
Remove unnecessary React propTypes
from the production build.
You can save bandwidth by removing them.
Example
In
const Baz = () => (
<div />
);
Baz.propTypes = {
foo: React.PropTypes.string
};
Out
const Baz = () => (
<div />
);
Usage
Via .babelrc
(Recommended)
.babelrc
without options:
{
"env": {
"production": {
"plugins": ["transform-react-remove-prop-types"]
}
}
}
with options:
{
"env": {
"production": {
"plugins": ["transform-react-remove-prop-types", {"mode": "wrap"}]
}
}
}
Via CLI
babel --plugins transform-react-remove-prop-types script.js
Via Node API
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'},
],
],
});
Options
mode
two modes are availableremove
(default): thepropTypes
definitions are removed from the source code.wrap
: thepropTypes
definitions are wrapped with the following code:
if (process.env.NODE_ENV !== "production") {
Foo.propTypes = {
bar: React.PropTypes.string,
};
}
This mode is quite useful for lib authors.
However, there is some limitation.
We do not support the old React.createClass
syntax nor the
name less classes yet. In those cases, we keep the propTypes
.
License
MIT