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

Should we mention babel-react-optimize? #9

Open
kurtextrem opened this issue Apr 27, 2018 · 3 comments · May be fixed by #14
Open

Should we mention babel-react-optimize? #9

kurtextrem opened this issue Apr 27, 2018 · 3 comments · May be fixed by #14

Comments

@kurtextrem
Copy link
Contributor

See here for more details: https://medium.com/doctolib-engineering/improve-react-performance-with-babel-16f1becfaa25
Personally, I'm using babel-plugin-transform-react-pure-class-to-function most of the time.
plugin-transform-react-inline-elements is buggy and disabled in create-react-app, same for plugin-transform-react-constant-elements as it hurts TTI - see: facebook/create-react-app#553 (comment)

@iamakulov
Copy link
Collaborator

So, to sum this up:

babel-react-optimize includes 4 plugins:

  • transform-react-inline-elements (buggy)
  • transform-react-constant-elements (potentially hurts time to interactive)
  • transform-react-remove-prop-types (already recommended)
  • transform-react-pure-class-to-function

Recommending transform-react-pure-class-to-function seems like a good idea – it could make the bundle smaller by removing Babel’s class helpers (see babel repl with class vs babel repl with function). We might want to revisit this in a couple of years though when IE (the only major browser not supporting classes) becomes less relevant.

Want to make a PR? :–)

@kurtextrem
Copy link
Contributor Author

Want to make a PR? :–)

Sure thing!
I also just got the idea to, if browserslist target allows, to transform:
function Foo(props){return exp}
to
const Foo=props=>exp

this saves another 11 bytes for single line returns and 2 for multiple statements. I wonder if it's worth it to create a plugin for that case.

@iamakulov
Copy link
Collaborator

iamakulov commented May 12, 2018

I wonder if it's worth it to create a plugin for that case.

Might worth it!

Such conversion might break the this/arguments/.bind()/etc references though, so the plugin would need to account for that. In general, applying it seems OK for React components (because they usually don’t rely on this or .bind()) but not OK for an arbitrary function.

kurtextrem added a commit to kurtextrem/webpack-libs-optimizations that referenced this issue Jun 20, 2018
@kurtextrem kurtextrem linked a pull request Jun 20, 2018 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants