Serve sources as well, and use X-SourceMap header.

Source maps now work in Chrome, if you enable them (dev tools -> gears button ->
enable source maps). I can't get them to work in FF 24 though.
This commit is contained in:
David Glasser
2013-07-09 12:45:15 -07:00
parent 31e560e8ca
commit c329ebf90d
2 changed files with 22 additions and 2 deletions

View File

@@ -245,6 +245,15 @@ var runWebAppServer = function () {
};
// Send the SourceMap header when the source file is served.
staticFile.sourceMap = sourceMapRootUrl;
// Now register all the sources from this source map to be served, under
// the source map's URL.
_.each(item.sources, function (x, pathForSourceMap) {
staticFiles[sourceMapRootUrl + pathForSourceMap] = {
path: x.source,
cacheable: true
};
});
}
staticFiles[url.parse(item.url).pathname] = staticFile;
}
@@ -293,7 +302,9 @@ var runWebAppServer = function () {
// Tell the client where to find the source map for this file.
if (info.sourceMap) {
res.setHeader('SourceMap', info.sourceMap);
// This should just be SourceMap, but slightly more browsers support the
// older X-SourceMap.
res.setHeader('X-SourceMap', info.sourceMap);
}
send(req, path.join(clientDir, info.path))

View File

@@ -902,7 +902,16 @@ _.extend(ClientTarget.prototype, {
data: new Buffer(file.sourceMap.toString(), 'utf8')
});
// XXX write sources too
manifestItem.sources = {};
_.each(file.sources, function (x, pathForSourceMap) {
manifestItem.sources[pathForSourceMap] = {
package: x.package,
sourcePath: x.sourcePath,
source: builder.writeToGeneratedFilename(
path.join('sources', pathForSourceMap),
{ data: x.source })
};
});
}
manifest.push(manifestItem);