This is primarily for the purpose of deploying to a production environment.
A solution that parses the JS file into an AST and then removes the console calls is preferable, but I’m willing to look at altneratives.
I’m especially interested in ones that can remove console.assert calls.
I handle this two ways:
1) I never use console.log() or any console calls in my code. For debugging purposes, I have my own debugging object with it’s own methods. I can then control with a single setting whether console messages go to the actual debug console, go to my own textarea object or do nothing. Thus I can turn them on or off or redirect them with one line of code.
2) I wrote my own python script that search my JS files for my own debugging calls and removes them. It also removes all comments, but does not minimize the file so it’s still fully debuggable. This is my “pre-production” or “beta” version of the code that I can freely let out in the world and it’s easy to track down problems in, but it doesn’t have all my comments and notes in the code. This particular python script isn’t super general purpose so I haven’t made it publicly available, but it wasn’t hard to write.