How to exclude/override plugins included by babel-preset-react-app

673 Views Asked by At

I want to use propTypes even in production mode (not recommended but my React app needs it). As you may know propTypes are removed by babel-plugin-transform-react-remove-prop-types plugin. this plugin is added by babel-preset-react-app in this file: node_modules/babel-preset-react-app/create.js line 199. In my React application i tried everything to exclude the plugin, but nothing works, any ideas?

react => 18.2.0

For overriding CRA config i use : 
react-app-rewired => 2.2.1
customize-cra => 1.0.0

Here is what i tried:

// .babelrc

{
  "presets": [
    [
      "react-app", {
      "exclude": [
        "babel-plugin-transform-react-remove-prop-types",
        "transform-react-remove-prop-types",
        "react-remove-prop-types"
      ]
    }]
  ]
}

// And i tried this : 
{
  "overrides": [
    {
      "presets": [
        [
          "react-app", {
          "exclude": [
            "babel-plugin-transform-react-remove-prop-types",
            "transform-react-remove-prop-types",
            "react-remove-prop-types"
          ]
        }]
      ]
    }
  ]
}

// and also tried to change plugin params
{
  "presets": ["react-app"],
  "plugins": [
    [
      "babel-plugin-transform-react-remove-prop-types",
      {
        "removeImport": false,
        "ignoreFilenames": [".*"]
      }
    ]
  ]
}
// config-overrides.js

const { override, removeInternalBabelPlugin, useBabelRc} = require("customize-cra");

module.exports = override(
    useBabelRc(),
    removeInternalBabelPlugin('babel-plugin-transform-react-remove-prop-types'),
    removeInternalBabelPlugin('transform-react-remove-prop-types'),
);
0

There are 0 best solutions below