fix(build): correctly generate source maps

This commit is contained in:
Nico Rehwaldt 2014-08-06 09:30:02 +02:00
parent fb86037cdd
commit cb21721210
2 changed files with 30 additions and 15 deletions

View File

@ -33,6 +33,34 @@ module.exports = function(grunt) {
return alias; return alias;
} }
function extractSourceMap(file) {
var content = grunt.file.read(file, { encoding: 'utf-8' });
var match = /\/\/# sourceMappingURL=data:application\/json;base64,(.*)/.exec(content);
if (match) {
var b = new Buffer(match[1] + '==', 'base64');
var s = b.toString();
s = s.replace(/\\\\/g, '/'); // convert \\ -> /
var dir = __dirname;
var dirPattern = dir.replace(/\\/g, '/').replace(/\./g, '\\.') + '/';
var pattern = new RegExp(dirPattern, 'g');
s = s.replace(pattern, '');
grunt.file.write('tmp/sourceMap.json', s, { encoding: 'utf-8' });
return 'tmp/sourceMap.json';
} else {
return null;
}
}
// project configuration // project configuration
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
@ -194,20 +222,7 @@ module.exports = function(grunt) {
sourceMap: true, sourceMap: true,
sourceMapIncludeSources: true, sourceMapIncludeSources: true,
sourceMapIn: function(file) { sourceMapIn: function(file) {
var content = grunt.file.read(file, { encoding: 'utf-8' }); return extractSourceMap(file);
var match = /\/\/# sourceMappingURL=data:application\/json;base64,(.*)/.exec(content);
if (match) {
var b = new Buffer(match[1] + '==', 'base64');
var s = b.toString();
grunt.file.write('tmp/sourceMap.json', s, { encoding: 'utf-8' });
return 'tmp/sourceMap.json';
} else {
return null;
}
} }
}, },
bowerViewer: { bowerViewer: {

View File

@ -34,7 +34,7 @@
"grunt": "^0.4.4", "grunt": "^0.4.4",
"grunt-browserify": "^2.1.2", "grunt-browserify": "^2.1.2",
"grunt-contrib-jshint": "^0.7.2", "grunt-contrib-jshint": "^0.7.2",
"grunt-contrib-uglify": "^0.4.1", "grunt-contrib-uglify": "https://github.com/gruntjs/grunt-contrib-uglify/archive/master.tar.gz",
"grunt-contrib-watch": "^0.5.3", "grunt-contrib-watch": "^0.5.3",
"grunt-jsdoc": "^0.5.1", "grunt-jsdoc": "^0.5.1",
"grunt-karma": "^0.8.0", "grunt-karma": "^0.8.0",