This question is not specific to Sublime Text at all, or any text editor, but a generic question how to preprocess and debug (JavaScript) source code.
First, the easiest approach would be have some kind of global debug flag in your codebase.
window.DEBUG = true;
function log(a, b, c, d) {
if(DEBUG) {
console.log(a, b, c, d);
}
}
if(DEBUG) {
// Do dev stuff
} else {
// Do produection stuff
}
log("foobar") // Does not need to be wrapper, as log() itself is functional only in debug mode
You can set the debug flag depending on your URL:
if(window.location.href.indexOf("localhost") >= 0) {
window.DEBUG = true;
}
When you deploy your JavaScript to production, you usually run it through minimizing and bundling tool. One popular tool is UglifyJS 2 which features constant elimination. When running and deploying your JavaScript code with this tool, if(DEBUG) { }
parts of your code gets eliminated.
You can connect any tool to Sublime Text using Project > Build scripts.
For the server-side code, you simply need to set debug flag depending on your environment. Each framework (Ruby on rails) have their own way of doing this, and you need to ask specific details in framework specific question.