Ok, so stumbled on the answer while looking for something else and since no one had yet responded. Here is how I solved it:
You get a copy of Grunt Preprocess with
npm install --save-dev grunt-preprocess
Then you modify your GruntFile.js
like so (this is for an angular project, YMMV)
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-preprocess'); <-- Add this line near the top of the file
add this in your list of subtasks
preprocess : {
options: {
inline: true,
context : {
DEBUG: false
}
},
html : {
src : [
'<%= yeoman.dist %>/index.html',
'<%= yeoman.dist %>/views/*.html'
]
},
js : {
src: '.tmp/concat/scripts/*.js'
}
},
Modify your registered tasks (at the bottom of the file) like thils:
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'preprocess:js', // Remove DEBUG code from production builds
'preprocess:html', // Remove DEBUG code from production builds
'ngmin',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'rev',
'usemin'
]);
Then modify your existing javascript code something like this:
// @if DEBUG
'server_mocks', // Won't be included in production builds
// @endif
and your existing html code something like this:
<!-- @if DEBUG -->
<script src='scripts/mock.js'></script> <!-- Won't be included in production builds -->
<!-- @endif -->