oliviertassinari / babel-plugin-transform-react-remove-prop-types

Remove unnecessary React propTypes from the production build. :balloon:
MIT License
897 stars 61 forks source link

No support for babel 7 #156

Closed twchn closed 5 years ago

twchn commented 6 years ago

I used babel 7 with .babelrc and followed the README, but I found it's useless to write

{
  "env": {
    "production": {
      "plugins": ["transform-react-remove-prop-types"]
    }
  }
}

in .babelrc. However, when I only wrote "plugins": ["transform-react-remove-prop-types"], it works in any environment(development & production).

oliviertassinari commented 5 years ago

@taoweicn I don't understand, what's the point?

twchn commented 5 years ago

@taoweicn I don't understand, what's the point?

The code below both are my .babelrc config.

When I wrote this, it will NOT work in babel7:

{
  "env": {
    "production": {
      "plugins": ["transform-react-remove-prop-types"]
    }
  }
}

When I wrote this, it will work in both development and production environment:

{
  "plugins": ["transform-react-remove-prop-types"]
}
oliviertassinari commented 5 years ago

@taoweicn If you don't set NODE_ENV=production or BABEL_ENV=production, it's not a surprise.

karolisgrinkevicius-home24 commented 5 years ago

For me it works in the same way as @taoweicn has mentioned. I'm using

├── @babel/core@7.2.2
├── babel-plugin-transform-react-remove-prop-types@0.4.24
└── react@16.6.3

and the following .babelrc configuration:

{
  "presets": [
    [
      "@babel/env",
      {
        "targets": {
          "browsers": ["last 2 versions"]
        },
        "modules": false,
        "useBuiltIns": "entry"
      }
    ],
    "@babel/react",
    "@babel/flow"
  ],
  "ignore": ["node_modules", "dist"],
  "plugins": ["react-hot-loader/babel", "@babel/plugin-proposal-class-properties", "@babel/transform-classes"],
  "env": {
    "production": {
      "plugins": ["transform-react-remove-prop-types", "react-remove-properties"]
    },
    "development": {
      "plugins": ["flow-react-proptypes"]
    }
  }
}

I also set the environment variable BABEL_ENV to production.

oliviertassinari commented 5 years ago

I think that you fill find better luck on the Babel side. If you can provide a failing test case, it would help.