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
Implement plugin-transform-react-pure-annotations
and add to preset-react
#11428
Implement plugin-transform-react-pure-annotations
and add to preset-react
#11428
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
I would like the plugin to be named @babel/plugin-transform-react-pure-annotations
, since I find it more descriptive of what it does.
Apart from that, the code looks good 👍
The CI failure doesn't seem related to this PR, but it doesn't fail on master and it fails on every node version 🤔 |
Ok, I restarted travis on master and it failed. |
Updated the plugin name. I'm not sure what's up with the tests. They do pass locally... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fixed by #11432
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
6a17bde
to
6d80d8d
Compare
plugin-transform-react-pure-annotations
and add to preset-react
This implements
@babel/plugin-transform-react-pure
as described in #11399, and adds it by default to@babel/preset-react
. This plugin adds/*#__PURE__*/
annotations before many top-level React function calls, which allows them to be tree shaken/dead code eliminated by terser and other minifiers.For example, libraries making use of
React.forwardRef
orReact.memo
could be tree shaken if unused. For apps using large libraries of components that use these APIs, this could make a big difference to overall bundle size.This is built into
@babel/preset-react
by default for maximum impact across the ecosystem. However, it can be disabled by setting the{"pure": false}
option to the preset, which also already disables pure annotations on compiled JSX.