-
Notifications
You must be signed in to change notification settings - Fork 639
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
Allow customizing the babel transform runtime version #771
Allow customizing the babel transform runtime version #771
Conversation
extraPlugins.push([ | ||
require('@babel/plugin-transform-runtime'), | ||
{ | ||
helpers: true, | ||
regenerator: !isHermes, | ||
version: isVersion ? options.enableBabelRuntime : '7.0.0-beta.0', |
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.
Can we avoid baking in the plugin's default fallback version?
version: isVersion ? options.enableBabelRuntime : '7.0.0-beta.0', | |
...(isVersion && {version: options.enableBabelRuntime}), |
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.
Yes definitely - I like this mechanism for initializing a specific property only under certain circumstances.
Thanks again @newyankeecodeshop - this looks like a useful optimisation |
@rh389 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Just confirming, does this mean we need to update the overload version each time to benefit from latest With the -6% bundle? Just thinking how to automate, might look into a |
@leotm You don't have to update the version each time you upgrade your babel necessarily. Setting the version to a reasonably newer version, such as |
Summary
As described in PR #714 , when the bundle is built using a recent version of babel, some helpers are defined repeatedly instead of being referenced via the runtime. In our case,
_getRequireWildcardCache()
and_interopRequireWildcard()
.Since the react native preset configures
@babel/plugin-transform-runtime
whenenableBabelRuntime
is enabled, I thought it would be straightforward to overload this metro configuration option to allow the runtime version to be specified. Therefore, changingbabel.config.js
to be:The above would both enable the runtime and configure it to use version
7.14.5
behaviors. An app developer can doyarn why @babel/runtime
to determine the runtime version and specify it in this configuration.Adding this option doesn't change the behavior for existing users who are using
true | false | undefined
for the babel runtime configuration.Test plan
All unit tests pass.
I modified our application as specified above while referencing my modified build of metro. The bundle showed a 6% size reduction and
_interopRequireWildcard
was required via the runtime.