Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Closure Compiler - Dead code removal based on externs
    text
    copied!<p>I'm trying to use the Google Closure Compiler to split my application code based on where it's going to be run (on the server vs the client) via a single variable. In this example, everything that's going to be called on the server is behind an <code>isServerSide</code> var, BUT, the code is being compiled for the client. So I'll set <code>isServerSide</code> to false and let the compiler remove everything that wouldn't be run by the client...</p> <p>Inside of <code>app.js</code>:</p> <pre><code>goog.provide('my.app'); my.app.log = function(message) { document.write(message); } my.app.initClientSide = function() { my.app.log('hello client'); } my.app.initServerSide = function() { my.app.log('hello server'); } if (isServerSide) { my.app.log('initing server'); my.app.initServerSide() }else my.app.initClientSide(); </code></pre> <p>Inside of <code>externs.js</code>:</p> <pre><code>/** * @define {boolean} is server side? */ var isServerSide=false; </code></pre> <p>Command:</p> <pre><code>java -jar bin/compiler.jar --js closure-library/closure/goog/base.js --js app.js --externs externs.js --manage_closure_dependencies true --process_closure_primitives true --summary_detail_level 3 --warning_level VERBOSE --compilation_level=ADVANCED_OPTIMIZATIONS --closure_entry_point my.app </code></pre> <p>Expected output:</p> <pre><code>document.write("hello client"); </code></pre> <p>Actual output:</p> <pre><code>isServerSide?(document.write("initing server"),document.write("hello server")):document.write("hello client"); </code></pre> <p>If I manually type <code>isServerSide=false;</code> in <code>app.js</code> then I can get it to compile to this:</p> <pre><code>isServerSide=false;document.write("hello client"); </code></pre> <p>Which makes me think I'm setting up my <code>externs.js</code> wrong (or I just don't understand what externs should actually be used for).</p> <p>Any suggestions on how to get this working?</p>
 

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