fix(build): correctly generate source maps
This commit is contained in:
parent
fb86037cdd
commit
cb21721210
43
Gruntfile.js
43
Gruntfile.js
|
@ -33,6 +33,34 @@ module.exports = function(grunt) {
|
|||
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
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
|
@ -194,20 +222,7 @@ module.exports = function(grunt) {
|
|||
sourceMap: true,
|
||||
sourceMapIncludeSources: true,
|
||||
sourceMapIn: function(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();
|
||||
|
||||
grunt.file.write('tmp/sourceMap.json', s, { encoding: 'utf-8' });
|
||||
|
||||
return 'tmp/sourceMap.json';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return extractSourceMap(file);
|
||||
}
|
||||
},
|
||||
bowerViewer: {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
"grunt": "^0.4.4",
|
||||
"grunt-browserify": "^2.1.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-jsdoc": "^0.5.1",
|
||||
"grunt-karma": "^0.8.0",
|
||||
|
|
Loading…
Reference in New Issue