fix(sourcemap): add head.js sourcemap

Fixes mozilla/fxa-content-server#3355
This commit is contained in:
Vlad Filippov 2016-01-04 19:19:34 -05:00
Родитель e992193221
Коммит adfacf94f2
3 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -57,8 +57,10 @@ module.exports = function (grunt) {
// replaces the blocks by the file they reference,
// and replaces all references to assets by their revisioned version if it is found on the disk
'usemin',
// copy the non-minified scripts file for sourcemap purposes
// copy the non-minified main.js script file for sourcemap purposes
'copy:build',
// copy the non-minified head.js script file for sourcemap purposes
'copy:head',
// update the sourcemap path to match the hosted files
'sourcemap-source',

Просмотреть файл

@ -69,6 +69,14 @@ module.exports = function (grunt) {
src: 'en/{500,502,503}.html'
}]
},
head: {
files: [{
cwd: '<%= yeoman.tmp %>/concat/scripts',
dest: '<%= yeoman.dist %>/scripts',
expand: true,
src: ['**/*.js']
}]
},
// copy normalize.css to .tmp during build, this library is required by grunt-usemin to be in .tmp
normalize: {
dest: '<%= yeoman.tmp %>/bower_components/normalize-css/normalize.css',

Просмотреть файл

@ -10,13 +10,19 @@ module.exports = function (grunt) {
*/
var fs = require('fs');
var MAP_PATH = 'dist/scripts/main.js.map';
grunt.registerTask('sourcemap-source', 'Adjusts the sourcemap source file to match the hosted path.', function () {
var existingMap = JSON.parse(fs.readFileSync(MAP_PATH));
var MAP_PATH_MAIN = 'dist/scripts/main.js.map';
var existingMap = JSON.parse(fs.readFileSync(MAP_PATH_MAIN));
existingMap.sources = ['main.js'];
fs.writeFileSync(MAP_PATH_MAIN, JSON.stringify(existingMap));
var MAP_PATH_HEAD = 'dist/scripts/head.js.map';
var existingMapHead = JSON.parse(fs.readFileSync(MAP_PATH_HEAD));
existingMapHead.sources = ['head.js'];
fs.writeFileSync(MAP_PATH_HEAD, JSON.stringify(existingMapHead));
fs.writeFileSync(MAP_PATH, JSON.stringify(existingMap));
});
};