Skip to content

Instantly share code, notes, and snippets.

@igordelorenzi
Created September 4, 2014 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igordelorenzi/7662eb036f695adcd8ce to your computer and use it in GitHub Desktop.
Save igordelorenzi/7662eb036f695adcd8ce to your computer and use it in GitHub Desktop.
Task for copying JavaScript Source Map files from vendor (and bower_components) to dist directory.
grunt.registerTask('fixSourceMapping', function () {
var concat = grunt.config('concat'),
copy = grunt.config('copy'),
files = concat.generated.files,
i, src, sourceMapFiles = [];
for (i in files) {
if (files[i].dest === "dist/scripts/vendor.js") {
src = files[i].src;
break;
}
}
for (i in src) {
var file1 = src[i].replace(/.js/, '.map');
var file2 = src[i] + '.map';
if (grunt.file.exists(file1)) {
file1 = file1.replace(/client\//, '');
sourceMapFiles.push(file1);
}
if (grunt.file.exists(file2)) {
file2 = file2.replace(/client\//, '');
sourceMapFiles.push(file2);
}
}
copy.dist.files.push({
expand: true,
flatten: true,
cwd: "client",
dest: "dist/scripts",
src: sourceMapFiles,
filter: 'isFile'
});
grunt.config('copy', copy);
grunt.log.ok();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment