Skip to content

Handling inline source map files #22

@mattdesl

Description

@mattdesl

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. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions