-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
remove console calls on production #8337
Conversation
ac1e87a
to
326053c
Compare
Notice: The commit was amended to simplify my original transform function. |
Thanks, @Emilios1995, I'll post this internally at FB to ask teams if this affects them in any way and get back to you. |
We should keep console.error since that provides non-fatal error logging. You should also verify this doesn't break our console polyfill code and console error reporter code. |
const callee = path.get("callee") | ||
if (callee.matchesPattern("console", true) && !callee.matchesPattern("console.error")) { | ||
path.node.callee = template(` | ||
(function () { |
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.
Instead of creating a new function object each time, it might be simpler just to use Function.prototype
, which is a no-op function #jstrivia
So, @bestander, do you think it's safe to merge? |
@Emilios1995, it seems that we use console.log in some products internally even for prod builds. |
Well, we could just suggest in the docs to include the official transform-remove-console in the production environment of the user's own .babelrc |
Yes, @Emilios1995, I think it is a good idea, want to send a docs PR? |
Let's close this for now, feel free to reopen if there are more ideas |
I tried using
I also tested it on another project for the web, which is bundled with webpack and works as expected, so I didn't open an issue at the babel repo yet because it might be RN related. |
Summary: This PR adds a suggestion to the docs to use the `transform-remove-console` babel plugin in production to remove `console.*` calls. This information was previously in the docs, but was [removed](e759573) because the babel plugin [didn't work](#10412). But now it's working well, as reported [here](#10412 (comment)), so it would be helpful to add the suggestion again. Ideally, this would be done automatically, as I suggested in #8337 Closes #13651 Differential Revision: D4954872 Pulled By: hramos fbshipit-source-id: 89ae1b813c50e678f0826f16ef88c8604e13d889
Summary: This PR adds a suggestion to the docs to use the `transform-remove-console` babel plugin in production to remove `console.*` calls. This information was previously in the docs, but was [removed](facebook@e759573) because the babel plugin [didn't work](facebook#10412). But now it's working well, as reported [here](facebook#10412 (comment)), so it would be helpful to add the suggestion again. Ideally, this would be done automatically, as I suggested in facebook#8337 Closes facebook#13651 Differential Revision: D4954872 Pulled By: hramos fbshipit-source-id: 89ae1b813c50e678f0826f16ef88c8604e13d889
This adds to the
production
mode ofbabel-preset-react-native
, a plugin to delete calls to theconsole
while still preserving the side effects inside them.The motivation is the great improvement on performance on the code running on device after removing the calls to
console
methodsNote that although the plugin works as expected, I don't know if this could cause any inconveniences on the rest of the system.