Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including combine-source-map with all npm packages installed. Try it out:

var combineSourceMap = require("combine-source-map")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

combine-source-map v0.8.0

Add source maps of multiple files, offset them and then combine them into one source map

combine-source-map build status

Add source maps of multiple files, offset them and then combine them into one source map.

var convert = require('convert-source-map');
var combine = require('combine-source-map');

var fooComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] pzJylcbiJdfQ==';
var barComment = '//# sourceMappingURL=data:application/json;base64,eyJ2Z [..] VjaycpXG4iXX0=';

var fooFile = {
    source: '(function() {\n\n  console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + fooComment
  , sourceFile: 'foo.js'
var barFile = {
    source: '(function() {\n\n  console.log(alert(\'alerts suck\'));\n\n}).call(this);\n' + '\n' + barComment
  , sourceFile: 'bar.js'

var offset = { line: 2 };
var base64 = combine
  .addFile(fooFile, offset)
  .addFile(barFile, { line: offset.line + 8 })

var sm = convert.fromBase64(base64).toObject();
{ version: 3,
  file: 'bundle.js',
  sources: [ '', '' ],
  names: [],
   [ 'console.log(require \'./bar.js\')\n',
     'console.log(alert \'alerts suck\')\n' ] }


npm install combine-source-map



 * @name create
 * @function
 * @param file {String} optional name of the generated file
 * @param sourceRoot { String} optional sourceRoot of the map to be generated
 * @return {Object} Combiner instance to which source maps can be added and later combined

Combiner.prototype.addFile(opts, offset)

 * Adds map to underlying source map.
 * If source contains a source map comment that has the source of the original file inlined it will offset these
 * mappings and include them.
 * If no source map comment is found or it has no source inlined, mappings for the file will be generated and included
 * @name addMap
 * @function
 * @param opts {Object} { sourceFile: {String}, source: {String} }
 * @param offset {Object} { line: {Number}, column: {Number} }


* @name base64
* @function
* @return {String} base64 encoded combined source map


 * @name comment
 * @function
 * @return {String} base64 encoded sourceMappingUrl comment of the combined source map


 * @name removeComments
 * @function
 * @param src 
 * @return {String} src with all sourceMappingUrl comments removed


Read and run the more elaborate example in order to get a better idea how things work.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free