Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to write source map to file #176

Open
donaldpipowitch opened this issue Aug 14, 2014 · 2 comments
Open

Option to write source map to file #176

donaldpipowitch opened this issue Aug 14, 2014 · 2 comments

Comments

@donaldpipowitch
Copy link

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 + ' */';
}
@donaldpipowitch donaldpipowitch changed the title Write source map to file not comment Option to write source map to file Aug 14, 2014
@donaldpipowitch
Copy link
Author

I just made a pull request to grunt-rework to show how this could work: jney/grunt-rework#14.

@txchen
Copy link

txchen commented Feb 6, 2015

I like the idea. Can rework support this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants