Do any of the JS compressors allow you to do #ifdef-pre-processing-type things with JScript conditional compilation?
If @set to defines a “variable” couldn’t a JS compressor remove code that the conditional compilation logic defines at not compiled?
I’m a little unsure of JScript syntax but perhaps something like this
/*@cc_on
@set (@version = 1)
@if (@version == 1)
alert('Version 1');
@else
alert('Not version 1');
@end
@*/
could compress into
alert('Version 1');
Closure compiler can preserve comments via the @preserve annotation, but neither closure compiler not any other parse-tree based compressor does a good job with CC in general.
It’s a hard problem. Handling conditional compilation requires reasoning about multiple possible parse trees, instead of just one.
Some of the really simple compressors that just treat JS as a series of tokens instead of manipulating a parse tree might do better with conditional compilation but they do much worse overall at compressing.
One solution might be to compile all your source files except one that has conditional compilation directives and that simply exports variables that are used by the other source files.