Skip to content

Commit

Permalink
Fix sindresorhus#55, issue with sourcemap output
Browse files Browse the repository at this point in the history
This fixes issue sindresorhus#55 for me with css generated from less. Code adapted from `gulp-postcss`
  • Loading branch information
Saturate committed Mar 8, 2016
1 parent 8cc62f4 commit c002efc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var through = require('through2');
var applySourceMap = require('vinyl-sourcemaps-apply');
var autoprefixer = require('autoprefixer');
var postcss = require('postcss');
var path = require('path');

module.exports = function (opts) {
return through.obj(function (file, enc, cb) {
Expand All @@ -22,10 +23,16 @@ module.exports = function (opts) {
from: file.path,
to: file.path
}).then(function (res) {
var map;
file.contents = new Buffer(res.css);

if (res.map && file.sourceMap) {
applySourceMap(file, res.map.toString());
map = res.map.toJSON();
map.file = file.relative;
map.sources = [].map.call(map.sources, function (source) {
return path.join(path.dirname(file.relative), source);
})
applySourceMap(file, map);
}

var warnings = res.warnings();
Expand Down

0 comments on commit c002efc

Please sign in to comment.