You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 939B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # vinyl-sourcemaps-apply
  2. Apply a source map to a vinyl file, merging it with preexisting source maps.
  3. ## Usage:
  4. ```javascript
  5. var applySourceMap = require('vinyl-sourcemaps-apply');
  6. applySourceMap(vinylFile, sourceMap);
  7. ```
  8. ### Example (Gulp plugin):
  9. ```javascript
  10. var through = require('through2');
  11. var applySourceMap = require('vinyl-sourcemaps-apply');
  12. var myTransform = require('myTransform');
  13. module.exports = function(options) {
  14. function transform(file, encoding, callback) {
  15. // generate source maps if plugin source-map present
  16. if (file.sourceMap) {
  17. options.makeSourceMaps = true;
  18. }
  19. // do normal plugin logic
  20. var result = myTransform(file.contents, options);
  21. file.contents = new Buffer(result.code);
  22. // apply source map to the chain
  23. if (file.sourceMap) {
  24. applySourceMap(file, result.map);
  25. }
  26. this.push(file);
  27. callback();
  28. }
  29. return through.obj(transform);
  30. };
  31. ```