gulp-sass/index.js

39 lines
990 B
JavaScript
Raw Normal View History

var gutil = require("gulp-util");
var through = require("through2");
var assign = require("object-assign");
var path = require('path');
var sass = require("node-sass");
2013-09-01 01:53:11 +02:00
var PLUGIN_NAME = 'gulp-sass';
2014-01-05 16:15:20 +01:00
module.exports = function(options) {
return through.obj(function(file, enc, cb) {
2014-01-05 16:15:20 +01:00
if (file.isNull()) {
2014-01-19 09:39:41 +01:00
return cb(null, file);
2014-01-05 16:15:20 +01:00
}
if (file.isStream()) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
2014-01-20 22:41:36 +01:00
if (path.basename(file.path).indexOf('_') === 0) {
return cb();
}
2014-01-05 16:15:20 +01:00
var opts = assign({}, options);
opts.file = file.path;
2013-09-01 06:54:25 +02:00
var callback = function(error, obj) {
if (error) {
return cb(new gutil.PluginError(
PLUGIN_NAME, error.message + ' on line ' + error.line + ' in ' + error.file
));
2014-02-11 06:01:45 +01:00
}
file.contents = new Buffer(obj.css);
file.path = gutil.replaceExtension(file.path, '.css');
cb(null, file);
2014-01-19 09:39:41 +01:00
};
2013-09-01 06:54:25 +02:00
sass.render(opts, callback);
});
2014-01-19 09:39:41 +01:00
};