Skip to content

Commit

Permalink
Add React propTypes removal
Browse files Browse the repository at this point in the history
I originally started by adding this plugin to react-dates, but it seems
like we are going to want this in a lot of places, so it makes sense to
put it into our preset instead.

react-dates/react-dates#1322

For the default options, I decided to go with "wrap" as the mode, since
we are likely to use this more frequently in packages that are published
and consumed by other packages and apps, which aren't very compatible
with the "remove" option.

In our apps where this is not a concern, we will want to override this
to use the "remove" option in production and likely disable this plugin
entirely in development for better build speeds.
  • Loading branch information
lencioni committed Aug 29, 2018
1 parent 4b1aa94 commit 005afe2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,42 @@ You may override our default debug option by providing your own `debug` key.
}]]
}
```

## React PropTypes removal

This preset will remove propTypes using [babel-plugin-transform-react-remove-prop-types](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) with the following default options:

```js
{
mode: 'wrap',
additionalLibraries: ['airbnb-prop-types'],
ignoreFilenames: ['node_modules'],
}
```

To disable this transformation, use the `removePropTypes` option:

```json
{
"presets": [["airbnb", {
"removePropTypes": false
}]]
}
```

Default options can be overridden using the `removePropTypes` option. These
options will be shallow-merged with the defaults:

```json
{
"presets": [["airbnb", {
"removePropTypes": {
"mode": "remove"
}
}]]
}
```

For example, if you are using this plugin in a deployable app, you might want to
use the remove mode for your production build (and disable this transform
entirely in development for optimal build speeds).
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module.exports = function buildAirbnbPreset(context, options) {
require('babel-preset-react')
],
plugins: [
options && options.removePropTypes === false ? null : ['babel-plugin-transform-react-remove-prop-types', assign({
mode: 'wrap',
additionalLibraries: ['airbnb-prop-types'],
ignoreFilenames: ['node_modules'],
}, options.removePropTypes)],

options && options.modules === false ? null : modules,
options && options.modules === false ? null : ['babel-plugin-transform-strict-mode', { strictMode: true }],
[require('babel-plugin-transform-es2015-template-literals'), {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"babel-plugin-transform-exponentiation-operator": "^6.24.1",
"babel-plugin-transform-jscript": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.15",
"babel-plugin-transform-strict-mode": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
Expand Down

0 comments on commit 005afe2

Please sign in to comment.