babel-plugin-flow-react-proptypes icon indicating copy to clipboard operation
babel-plugin-flow-react-proptypes copied to clipboard

Add an option for adding NODE_ENV checks for minifiers

Open sohkai opened this issue 6 years ago • 3 comments

Consumers of a library should be able to access the library's proptypes in dev builds, but then be able to seamlessly strip them out for production.

See conversation on https://github.com/brigand/babel-plugin-flow-react-proptypes/issues/70#issuecomment-278551711.

TODO:

  • [x] add deadCode config option (see readme)
  • [x] dce for the propTypes object
  • [x] dce for exported types (export type Foo =)
  • [ ] dce for imported types (import type {Foo} from './Foo)
  • [ ] dce for the actual 'propTypes' property, both with the default assignment at end of file, and the the useStatic option (currently propTypes=null after minify)

sohkai avatar Dec 16 '17 03:12 sohkai

Hi, tried dead code and running into issues with deadCode: true

Error: Error: No substitution given for "NODE_ENV". If this is not meant to be a
            placeholder you may want to consider passing one of the following options to @babel/template:
            - { placeholderPattern: false, placeholderWhitelist: new Set(['NODE_ENV'])}
            - { placeholderPattern: /^NODE_ENV$/ }

any suggestion on fix?

dlebedynskyi avatar Sep 04 '18 19:09 dlebedynskyi

@dlebedynskyi Thanks for the report, should be fixed in 24.1.2

brigand avatar Sep 04 '18 20:09 brigand

@brigand confirmed, working now. Thank you

dlebedynskyi avatar Sep 04 '18 21:09 dlebedynskyi