In the ant-build-script docs, it says I can mark my scripts with comments to state which Javascript files to minify & concat.
<-- scripts concatenated and minified via build script -->
<script src="js/plugins.js"></script>
<cript src="js/main.js"></script>
<-- end scripts -->
Is there a way I can use a similar approach to disable debug output, or remove specific lines in any files (Javascript, PHP, etc.)
An example of what I'm trying to accomplish:
<!-- Remove these lines -->
console.log("Starting test");
console.log("Test 2");
<-- end remove these lines -->
Also, using that same example, if it could replace a line. An example of that is if I wanted it to change a variable from a local test directory to a remote production directory.
I hope that make sense and I appreciate any help.
Thanks!
If you are trying to remove lines of Javascript using the h5bp default Google Closure Compiler I suggest looking at @define JSDoc Tag
/** @define {boolean} */
var DEBUG = true;
Then, in your project.properties file look for: # Closure Compiler Options
and set: tool.closure.opts = --define DEBUG=false
Finally, wrap any code you want ignored, in production, in a conditional:
if (!DEBUG) {
console.log("Starting test");
console.log("Test 2");
}
The @define JSDoc Tag will help with your second question also.
/**
* @define {string}
*/
var AJAX_URL = 'http://localhost/';
console.log(AJAX_URL);
with the compilations options: --compilation_level ADVANCED_OPTIMIZATIONS --define AJAX_URL=\'http://example.com/\'
(Note: you made need to fiddle with the quote escaping, depending on your platform) the resulting code is:
console.log("http://example.com/");
There are many ways to go about this of course, see: