Skip to content

Option to write source map to file #176

@donaldpipowitch

Description

@donaldpipowitch

It would be great if rework could write a source map not only to a comment, but optionally to a file. It could look something like this (just pseudo code):

// rework/index.js
Rework.prototype.toString = function(options){
  options = options || {};
  var result = stringify(this.obj, options);
  if (options.sourcemap && !options.sourcemapAsObject) {
    if(!options.sourcemapAsFile) {
      result = result.code + '\n' + sourcemapToComment(result.map);
    } else {
      // options.sourcemapAsFile could be a boolean so filePath will be dest file appended with ".map" or it could be a string with custom path
      var filePath = get file path from options.sourcemapAsFile;
      result = result.code + '\n' + sourcemapToFile(result.map, filePath);
    }
  }
  return result;
};

function sourcemapToFile(map, filePath) {
  var convertSourceMap = require('convert-source-map');
  fs.writeFilSync(filePath, convertSourceMap.fromObject(map));
  return '/*# sourceMappingURL=' + filePath + ' */';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions