diff --git a/README.md b/README.md index 3467253..f8166c8 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/index.js b/index.js index 7dd0222..65f9d00 100644 --- a/index.js +++ b/index.js @@ -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'), { diff --git a/package.json b/package.json index 27914c5..3d74564 100644 --- a/package.json +++ b/package.json @@ -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",