You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sets the charset for inline source maps. Default: `utf8`
302
302
303
-
### Plugin developers only: How to add source map support to plugins
303
+
### Plugin developers only:
304
304
305
-
- Generate a source map for the transformation the plugin is applying
306
-
-**Important**: Make sure the paths in the generated source map (`file` and `sources`) are relative to `file.base` (e.g. use `file.relative`).
307
-
- Apply this source map to the vinyl `file`. E.g. by using [vinyl-sourcemaps-apply](https://github.com/floridoo/vinyl-sourcemaps-apply).
308
-
This combines the source map of this plugin with the source maps coming from plugins further up the chain.
309
-
- Add your plugin to the [wiki page](https://github.com/floridoo/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support)
305
+
-**How to add source map support to plugins**
310
306
311
-
#### Example:
307
+
- Generate a source map for the transformation the plugin is applying
308
+
-**Important**: Make sure the paths in the generated source map (`file` and `sources`) are relative to `file.base` (e.g. use `file.relative`).
309
+
- Apply this source map to the vinyl `file`. E.g. by using [vinyl-sourcemaps-apply](https://github.com/floridoo/vinyl-sourcemaps-apply).
310
+
This combines the source map of this plugin with the source maps coming from plugins further up the chain.
311
+
- Add your plugin to the [wiki page](https://github.com/floridoo/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support)
312
312
313
-
```javascript
314
-
var through =require('through2');
315
-
var applySourceMap =require('vinyl-sourcemaps-apply');
316
-
var myTransform =require('myTransform');
313
+
#### Example:
317
314
318
-
module.exports=function(options) {
315
+
```js
316
+
var through =require('through2');
317
+
var applySourceMap =require('vinyl-sourcemaps-apply');
318
+
var myTransform =require('myTransform');
319
319
320
-
functiontransform(file, encoding, callback) {
321
-
// generate source maps if plugin source-map present
322
-
if (file.sourceMap) {
323
-
options.makeSourceMaps=true;
324
-
}
320
+
module.exports=function(options) {
321
+
322
+
functiontransform(file, encoding, callback) {
323
+
// generate source maps if plugin source-map present
324
+
if (file.sourceMap) {
325
+
options.makeSourceMaps=true;
326
+
}
327
+
328
+
// do normal plugin logic
329
+
var result =myTransform(file.contents, options);
330
+
file.contents=newBuffer(result.code);
325
331
326
-
// do normal plugin logic
327
-
var result =myTransform(file.contents, options);
328
-
file.contents=newBuffer(result.code);
332
+
// apply source map to the chain
333
+
if (file.sourceMap) {
334
+
applySourceMap(file, result.map);
335
+
}
329
336
330
-
// apply source map to the chain
331
-
if (file.sourceMap) {
332
-
applySourceMap(file, result.map);
337
+
this.push(file);
338
+
callback();
333
339
}
334
340
335
-
this.push(file);
336
-
callback();
337
-
}
341
+
returnthrough.obj(transform);
342
+
};
343
+
```
338
344
339
-
returnthrough.obj(transform);
340
-
};
341
-
```
345
+
-**Very sourcemaps is working**
346
+
347
+
See example below or refer to [test/write.js](./test/write.js)
0 commit comments