4

Iam using Visual studio

Iam having javascript codes scattered in different files.

Currently iam using below link's compressor

http://yuicompressor.codeplex.com/

this generates output as combined+minified files on project build.

i am looking for some way to remove all console.log statements from my codes in minified files. Please suggest me how to do this.

Praveen Prasad
  • 29,661
  • 16
  • 67
  • 104
  • That won't help you, but ideally you would have a build script that only includes `console.log` in development mode. This could be done with e.g. ant and the C preprocessor (cpp). – Felix Kling Jan 06 '11 at 15:38
  • See also https://stackoverflow.com/questions/20092466/can-uglify-js-remove-the-console-log-statements – Radek Svítil Feb 15 '18 at 17:14

2 Answers2

1

Why not just do this:

window['console'] = { log: function() {} };

when you don't want the "console.log" statements to do anything?

Pointy
  • 371,531
  • 55
  • 528
  • 584
  • iam looking for some way in visual studio, too get rid of unnecessary code. Rather than doing this. A build event that would merge all files and get rid of console thing. – Praveen Prasad Jan 06 '11 at 15:56
  • 1
    OK, well I'm not a Visual Studio expert, so I regret that I cannot help with that. – Pointy Jan 06 '11 at 15:59
0

Manually, you can use your editor, such as Visual Studio and with Search and Replace functionality use RegEx to remove all of your console logs.

With regex such as this:

console\.log(\((\").*\"\);+|\((\').*\'\);+)

You will be able to match all console.logs with " or ' wrapping strings.

Then you replace then with empty string.

You have to select g flag, or GLOBAL option or Replace All button.

Also consider, that console object has multiple methods, such as dir, table, group, etc...

Jakub Kriz
  • 1,467
  • 2
  • 21
  • 28