-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathgulp-autoprefixer-map.js
71 lines (48 loc) · 1.51 KB
/
gulp-autoprefixer-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
/*
Hack to enable source maps in with gulp-sourcemaps and autoprefixer.
Created by null on 12/08/14.
npm --save-dev install through2
npm --save-dev install autoprefixer
npm --save-dev install vinyl-sourcemaps-apply
var prefixer = require('./gulp-autoprefixer-map.js');
gulp.task('css', [], function() {
.pipe(sourcemaps.init())
.pipe(prefixer())
.pipe(sourcemaps.write('.'))
});
*/
var through = require('through2');
var prefix = require('autoprefixer');
//var applySourceMap = require('vinyl-sourcemaps-apply');
module.exports = function(browsers, options) {
options = options || {};
return through.obj(function(file, enc, cb) {
if(file.isStream()) {
throw new Error('Streams not supported');
}
if(!file.isNull()) {
if(file.sourceMap) {
options.map = {
prev: file.sourceMap.mappings ? file.sourceMap : undefined,
annotation: false,
sourcesContent: true
};
options.to = options.from = file.relative;
}
var contents = file.contents.toString();
var result = prefix.apply(this, browsers).process(contents, options);
contents = result.css;
file.contents = new Buffer(contents);
if(file.sourceMap) {
var map = JSON.parse(result.map.toString());
map.sources = file.sourceMap.sources;
map.file = file.sourceMap.file;
file.sourceMap = map;
//applySourceMap(file, map);
}
}
this.push(file);
cb();
});
};