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

Add support for defining additionalLibraries as a regexp expression #174

Closed pkuczynski closed 5 years ago

pkuczynski commented 5 years ago

This PR brings new feature (from README.md)


Regular expressions

If you are using Babel 7 or newer and your config is stored in babel.config.js, you can also use a regular expression to describe modules, which should be removed.

This would be particularly useful when using custom prop types validators, implemented as part of your own source code. For example

 import CustomPropTypes from '../../prop-types/my-own-validator'
 import OtherCustomPropTypes from '../../prop-types/my-other-validator'

would be removed with the following setting

 additionalLibraries: [/\/prop-types\/.*$/]

If you use an index file

 import CustomPropTypes from '../../prop-types'

you could set it up as

 additionalLibraries: [/\/prop-types$/]
pkuczynski commented 5 years ago

Do you want me to add some tests before you merge it in?

oliviertassinari commented 5 years ago

@pkuczynski One simple test would be great :)

pkuczynski commented 5 years ago

Sure! The only reason why I haven’t done this so far was that I wasn’t really sure if you would accept this contribution and like the idea.

I will add a test tomorrow, when I get back to my laptop.

Any chance this would be merged and released anytime soon?

oliviertassinari commented 5 years ago

Yes, we can release quickly after.

pkuczynski commented 5 years ago

Tests added. I change path-exists to globby, as it makes it a bit easier to require files by the pattern. I hope you don't mind?

pkuczynski commented 5 years ago

Looking forward to hearing some feedback for you and get this released...

oliviertassinari commented 5 years ago

@pkuczynski Thank you

pkuczynski commented 5 years ago

Thanks! :)