combine-source-map
combine-source-map copied to clipboard
Handling inline source map files
I have the following scenario:
- I have a file which may or may not include source map comment (either inline or as a map file)
- I want to wrap this file with a closure that injects some global values
- I want source maps to work nicely so that Chrome DevTools hides this ugly closure function (header / footer)
Is this possible using this module? I am currently using something like this, but Chrome DevTools is not handling source maps for content with a relative sourceMappingURL map file. Those with inline base64 data are working fine.
var combineSourceMap = require('combine-source-map');
var prelude = [
'(function (__blah) {',
'\n});'
];
var originalSource = fs.readFileSync(...);
var wrappedSource = prelude[0] + originalSource + prelude[1];
var sourceFile = path.relative(basedir, currentFile).replace(/\\/g, '/');
var sourceFileName = path.basename(sourceFile);
var sourceFileDir = path.dirname(sourceFile);
var sourceMap = combineSourceMap.create(sourceFileName, sourceFileDir)
.addFile({ sourceFile: sourceFile, source: originalSourceContent });
// replace existing comments with new base64 data
var finalSource = [
combineSourceMap.removeComments(wrappedSource),
sourceMap.comment()
].join('\n');
Thanks for the great module. :smile: