Last active
August 29, 2015 14:05
-
-
Save McNull/1331b911736c90dbae06 to your computer and use it in GitHub Desktop.
Hack to enable source maps in with gulp-sourcemaps and autoprefixer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 sourcemaps = require('gulp-sourcemaps'); | |
var concat = require('gulp-concat'); // Supports gulp-sourcemaps | |
var prefixer = require('./gulp-autoprefixer-map.js'); | |
gulp.task('css', [], function() { | |
gulp.src('src/*.css') | |
.pipe(sourcemaps.init()) | |
.pipe(concat('app.css')) | |
.pipe(prefixer()) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('dest/')) | |
}); | |
*/ | |
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 = { | |
annotation: false | |
}; | |
options.to = options.from = file.relative; | |
} | |
var contents = file.contents.toString(); | |
var result = prefix(browsers).process(contents, options); | |
contents = result.css; | |
file.contents = new Buffer(contents); | |
if(file.sourceMap) { | |
applySourceMap(file, result.map.toString()); | |
} | |
} | |
this.push(file); | |
cb(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment