Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strategy for stripping propTypes from external packages #38

Closed
avindra opened this issue Jul 28, 2016 · 3 comments
Closed

Strategy for stripping propTypes from external packages #38

avindra opened this issue Jul 28, 2016 · 3 comments
Labels

Comments

@avindra
Copy link

avindra commented Jul 28, 2016

This is a question.

Say I have a .babelrc file like this:

{
  "presets": ["react", "es2015", "stage-1"],
  "env" : {
    "development" : {
        "presets" : ["react-hmre"]
    },
    "production" : {
        "plugins" : ["transform-react-remove-prop-types"]
    }
  }
}

And I'm building my project with webpack, so my JS loader looks like this:

            {
                test : /\.jsx?$/,
                exclude : /(?:node_modules)/,
                loaders : [ 'babel', 'eslint' ],
            },

As you can see node_modules are excluded, because running the transformer on npm code would be excessive / expensive. However, doing so means propType definitions from packages such as react-datepicker and react-autosuggest will remain in the final build.

So my question is, what would be the smartest strategy for removing propTypes from external packages in a setup like this?

Should we be convincing package authors to add this plugin to their builds with the wrap mode on?


P.S., I've tried just running the babel cli tool to strip propTypes from the compiled build, but that doesn't work (I guess, due to safeguards within your package to validate variables named propTypes are actually React related).

@oliviertassinari
Copy link
Owner

oliviertassinari commented Jul 28, 2016

Should we be convincing package authors to add this plugin to their builds with the wrap mode on?

I think that convincing package authors to use the wrap option of this plugin would be an efficient strategy.
Most of them are already publishing an es5 version of their package using Babel.

For one moment, I was worried about how we would handle es6 published version.
No much package authors are publishing one as we are speaking, I don't have any test running under those conditions, but I believe it's already supported. #fingercrossed 🎌 .

I have no clue regarding package authors using TypeScript.

I've tried just running the babel cli tool to strip propTypes from the compiled build

That's an interesting approach. We should support it, I have never tried it.

@oliviertassinari
Copy link
Owner

oliviertassinari commented Jul 28, 2016

@avindra I have added a test with an already transpiled code. It's not working for all the cases. #39.

@oliviertassinari
Copy link
Owner

I'm closing this issue. The wrap mode is used in production with Material-UI (.babelrc). This approach is working for us so far. We might have some edge cases. But I'm confident, we can address them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants