-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
44 lines (35 loc) · 920 Bytes
/
index.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
var through = require( "through" );
var sass = require( "node-sass" );
var path = require( "path" );
module.exports = function( file, opts ) {
opts = opts || {};
var includePaths = opts.includePaths;
delete opts.includePaths;
var data = "";
if( file !== undefined && path.extname( file ) !== ".scss" )
return through();
else {
return through( write, end );
}
function write(buf) {
data += buf;
}
function end() {
try {
var sassOpts = opts;
sassOpts.data = data;
var pathToAdd = [ path.dirname( file ) ];
sassOpts.includePaths = Array.isArray( includePaths ) ?
includePaths.concat( pathToAdd ) :
pathToAdd;
var result = sass.renderSync( sassOpts );
if( result instanceof Error ) {
throw result;
}
this.queue( result.css );
} catch( err ) {
this.emit( 'error', new Error( err ) );
}
this.queue( null );
}
};