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