Skip to content

Conversation

candrews
Copy link

Add a environment variable, DROP_CONSOLE, to specify if console
function calls should be dropped in the production build.

Supersedes #9221

@stale
Copy link

stale bot commented Jul 25, 2020

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jul 25, 2020
@candrews
Copy link
Author

@eddiemonge @ianschmitz what are your thoughts on this?

I believe it addresses the concerns expressed in my earlier PR, and I think it would be a great improvement to CRA.

Thanks in advance!

@stale stale bot removed the stale label Jul 25, 2020
@eddiemonge
Copy link
Contributor

This seems reasonable to me.

Another way I know of doing this on a per project basis is to create a logging utility function that wraps console call somewhat like this:

export const log = (...args) {
  if (process.env.NODE_ENV !== 'production') {
    console.log(...args);
  }
}

If the env is production then the code is removed at build time.

@candrews
Copy link
Author

candrews commented Aug 4, 2020

@iansu @amyrlam @mrmckeb @ianschmitz @petetnt Can you please take a look at this PR?

I believe that this approach to removing console statements from production builds is easy, safe, maintainable, and very much desirable for end users.

If there are further changes I can make to this PR to make it more acceptable and/or appealing, please let me know. I'm eager to get (or a functionally equivalent) change accepted.

Thanks again!

@amyrlam amyrlam removed their request for review August 24, 2020 05:41
@hutch120
Copy link

This PR would be welcomed by the community here
https://stackoverflow.com/questions/47839311/removing-log-statements-in-create-react-app-without-ejecting/53770988#53770988

@hutch120
Copy link

Anything I can help with to progress this PR? My two cents... the code change is identical code style to the other environment checks such as shouldUseSourceMap.

I took a look at the two failing checks, but there is no detail on why they failed.

@hutch120
Copy link

hutch120 commented Nov 6, 2020

Just another note of support for this PR ... using the popular snippet if (!dev) { console.log = () => {} } in a library module will unintentionally remove console.log messages in development mode for modules that use that library.

Add a environment variable, `DROP_CONSOLE`, to specify if console
function calls should be dropped in the production build.
@candrews
Copy link
Author

@ianschmitz @eddiemonge @mrmckeb @petetnt (and anyone else) can you please look at this PR? I believe it meets all requirements for a contribution and addresses an issue requested by CRA users. If there's anything I can do to move this along, please tell me - it's been a long time and I'd really like to see some progress (or at least feedback) on this PR.

Thank you in advance!

@hutch120
Copy link

hutch120 commented Feb 1, 2021

@ianschmitz Thanks for adding the tag new feature, just wondering does that indicate there an ETA for accepting/rejecting the PR? Next major release or something?

@yepes
Copy link

yepes commented May 7, 2021

Any ETA on this? Would be nice to have this implemented guys

@alvaroschipper
Copy link

Bump

@benkingcode
Copy link

Can someone please review this

cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Jul 28, 2022
cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Jul 28, 2022
@cliffoo
Copy link

cliffoo commented Jul 29, 2022

Another gentle nudge. Can someone from facebook (@ianschmitz ?) take a bit of time to approve / give feedback on this? It would be highly appreciated. Eject is not the way.

cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Aug 2, 2022
cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Aug 2, 2022
cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Aug 17, 2022
cliffoo pushed a commit to ConsenSys-archive/truffle that referenced this pull request Aug 18, 2022
@hutch120
Copy link

Just a quick update on this, I still get upvotes on my response to this issue on StackOverflow and the issue has over 10K views. Seems like this is still a relevant topic for some people, personally I've given up on this ever being actioned, but would be nice to have some closure here one way or the other so we can all move on. https://stackoverflow.com/questions/47839311/removing-log-statements-in-create-react-app-without-ejecting/53770988#53770988

@candrews
Copy link
Author

@jackblackevo @matrush @rvdende @danielrentz @sdarnadeem @pawelskowronek @nvh95 @JSLGeeganage and anyone else - can you please review this (simple) MR and let us know what needs to be done to merge it, or why it cannot be mergeable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants