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

Strip PropTypes from production builds #8

Closed
ziir opened this issue Apr 30, 2018 · 5 comments
Closed

Strip PropTypes from production builds #8

ziir opened this issue Apr 30, 2018 · 5 comments

Comments

@ziir
Copy link

ziir commented Apr 30, 2018

Though we use Flow almost everywhere, there are still quite a lot of PropTypes left in our production bundles.

In a typical production bundle, .propTypes search gives ~150 occurences.

We'd gain precious bytes by using a plugin such as babel-plugin-transform-react-remove-prop-types in production builds while we progressively get rid of propTypes alltogether.

@pascalduez
Copy link
Member

pascalduez commented May 2, 2018

This could be easily done in our Apps webpack config. Just add that plugin for the production build.
But I'm afraid the size gain might be negligible.
Especially if we envision that they should progressively be removed anyway. (Flow, new context API).

For libs it's not really worst it.
node_modules are excluded from the babel-loader (for good reasons I guess).
So if we add it here, there won't be proptypes for dev, which is the main goal of proptypes.
As for libs shipping a dev and prod versions that feels like a lot of complexity ahead for again small gains.

To me the most significant size gain we can have are:

@ziir
Copy link
Author

ziir commented May 2, 2018

Yeah, I forgot about our libs...

But, about:

node_modules are excluded from the babel-loader (for good reasons I guess).

If we move forward with #5

Then we will apply babel-loader to all our internal libraries in our bundles compilation.
So applying this plugin only in bundle compilation will result in propTypes being stripped:

  • from the app code
  • from our libraries code

So we can use this plugin in our webpack config today, and it'll be ~really worth it the day we tackle #5

Thanks for sharing your insights, we definitely to get on these

@pascalduez
Copy link
Member

pascalduez commented May 2, 2018

Then we will apply babel-loader to all our internal libraries in our bundles compilation.

I'm concerned about build time, especially in dev, but everything's open.

Food for thoughts:
facebook/create-react-app#1125
gatsbyjs/gatsby#2114

@ziir
Copy link
Author

ziir commented May 3, 2018

I think there's no reason for us to compile the legacy bundle in development, so build time increase should not be an issue.

The main thing I'm gathering from these discussions is that applying babel-loader to the entire node_modules might not be safe, which I would agree.
We will only need to apply it to @gandi scoped packages, over which we have control.

@ziir
Copy link
Author

ziir commented Nov 13, 2019

Closing this as no longer relevant.

We are applying babel-plugin-transform-react-remove-prop-types on a limited set of node_modules packages, during the production client-side bundle compilation, with little gains.

@ziir ziir closed this as completed Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants