Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving console.log with closure compiler
    primarykey
    data
    text
    <p>I'd like to make my JS code production ready by stripping out all <code>console.log("blah blah")</code> debugging statements. I'm confused by <a href="https://stackoverflow.com/questions/2934509/exclude-debug-javascript-code-during-minification#answer-5969752">this popular SO answer (code below)</a> on how to do this using <a href="https://developers.google.com/closure/compiler/" rel="nofollow noreferrer">Google's closure compiler</a>, a popular JS minifier/compiler.</p> <pre><code>/** @const */ var LOG = false; ... LOG &amp;&amp; log('hello world !'); // compiler will remove this line ... //this will even work with `SIMPLE_OPTIMALIZATIONS` and no `--define=` is necessary ! </code></pre> <p><strong>Two questions:</strong></p> <ol> <li><p><em>Multiples files:</em> How does the above code work with multiple files (basic example below)? It has to be in a closure, right? Doesn't this then mean you have to put this code on each page? Also, doesn't it also then mean you have to change all the variables you want to be global from <code>var foo='bar'</code> to <code>var window.foo='bar';</code> inside these closures on each page? </p></li> <li><p>Minor issue: Shouldn't it be <code>console.log('...')</code> rather than <code>log('...')</code> because <code>log()</code> gives an error? Am I missing something obvious here?</p></li> </ol> <p><code> &lt;script src='/assets/js/file1.js'&gt;&lt;/script&gt; &lt;script src='/assets/js/file2.js'&gt;&lt;/script&gt; </code></p> <p>contents of file1.js:</p> <pre><code>var foo='bar'; console.log("foo"+foo); </code></pre> <p>contents of file2.js</p> <pre><code>var baz='bazzy'; console.log("baz"+baz); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload