Created
August 6, 2012 15:16
-
-
Save ehynds/3275345 to your computer and use it in GitHub Desktop.
Grunt task to remove console logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.registerMultiTask("removelogging", "Remove console logging", function() { | |
var done = this.async(); | |
var exec = require("child_process").exec; | |
var options = this.data.options || {}; | |
grunt.file.expandFiles(this.data.files).forEach(function(file) { | |
var cmd = "sed -E 's/console\.(log|warn|error|assert|count|clear|group|groupEnd|trace|debug|dir|dirxml|profile|profileEnd|time|timeEnd)\((.*)\);?//g' " + file; | |
exec(cmd, options, function(error, stdout) { | |
if(error !== null) { | |
grunt.log.error('exec error: ' + error); | |
return; | |
} | |
grunt.file.write(file, stdout); | |
done(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.initConfig({ | |
removelogging: { | |
dist: { | |
files: [ "dist/file.js" ], | |
// options to pass to exec: http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback | |
options: { | |
maxBuffer: 1024 * 1024 | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those who arrived at this through a Google search there's a more recently updated npm module that does this https://github.com/ehynds/grunt-remove-logging