merge
commit
22fe33db96
|
@ -42,6 +42,10 @@ Pass in your own callback to be called upon successful compilaton by node-sass.
|
|||
|
||||
Pass in your own callback to be called upon a sass error from node-sass. The callback has the form `callback(err)`, where err is the error string generated by libsass. Note: this *does* prevent an actual `gulpPluginError` object from being created.
|
||||
|
||||
#### `sync: true`
|
||||
|
||||
If you pass `sync: true` into the options hash, sass.renderSync will be called, instead of sass.render. This should help when memory and/or cpu usage is getting very high when rendering many and/or big files.
|
||||
|
||||
## Source Maps
|
||||
|
||||
gulp-sass can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) to generate source maps for the SASS to CSS compilation. You will need to initialize [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) prior to running the gulp-sass compiler and write the source maps after.
|
||||
|
|
23
index.js
23
index.js
|
@ -52,10 +52,7 @@ module.exports = function (options) {
|
|||
|
||||
applySourceMap(file, map);
|
||||
}
|
||||
|
||||
file.path = ext(file.path, '.css');
|
||||
file.contents = new Buffer(css);
|
||||
cb(null, file);
|
||||
handleOutput(css, file, cb);
|
||||
};
|
||||
|
||||
opts.error = function (err) {
|
||||
|
@ -72,7 +69,17 @@ module.exports = function (options) {
|
|||
return cb(new gutil.PluginError('gulp-sass', err));
|
||||
};
|
||||
|
||||
sass.render(opts);
|
||||
if ( opts.sync ) {
|
||||
try {
|
||||
var output = sass.renderSync(opts);
|
||||
opts.success(output, null);
|
||||
handleOutput(output, file, cb);
|
||||
} catch(err) {
|
||||
opts.error(err);
|
||||
}
|
||||
} else {
|
||||
sass.render(opts);
|
||||
}
|
||||
|
||||
if (addedLocalDirPath) opts.includePaths.pop();
|
||||
|
||||
|
@ -81,6 +88,12 @@ module.exports = function (options) {
|
|||
return map(nodeSass);
|
||||
};
|
||||
|
||||
function handleOutput(output, file, cb) {
|
||||
file.path = ext(file.path, '.css');
|
||||
file.contents = new Buffer(output);
|
||||
cb(null, file);
|
||||
}
|
||||
|
||||
function getSourcesContent (sources) {
|
||||
sourcesContent = [];
|
||||
|
||||
|
|
33
test/test.js
33
test/test.js
|
@ -58,6 +58,26 @@ test('compile a single sass file', function (t) {
|
|||
stream.write(sassFile);
|
||||
});
|
||||
|
||||
test('compile a single sass file synchronously', function (t) {
|
||||
var sassFile = createVinyl('mixins.scss');
|
||||
|
||||
var stream = gsass({sync: true});
|
||||
stream.on('data', function (cssFile) {
|
||||
t.ok(cssFile, 'cssFile should exist');
|
||||
t.ok(cssFile.path, 'cssFile.path should exist');
|
||||
t.ok(cssFile.relative, 'cssFile.relative should exist');
|
||||
t.ok(cssFile.contents, 'cssFile.contents should exist');
|
||||
t.equal(cssFile.path, path.join(__dirname, 'scss', 'mixins.css'));
|
||||
t.equal(
|
||||
fs.readFileSync(path.join(__dirname, 'ref/mixins.css'), 'utf8'),
|
||||
cssFile.contents.toString(),
|
||||
'file compiles correctly to css'
|
||||
);
|
||||
t.end();
|
||||
})
|
||||
stream.write(sassFile);
|
||||
});
|
||||
|
||||
test('compile multiple sass files', function (t) {
|
||||
var files = [
|
||||
createVinyl('inheritance.scss'),
|
||||
|
@ -94,6 +114,19 @@ test('emit error on sass errors', function (t) {
|
|||
stream.write(errorFile);
|
||||
});
|
||||
|
||||
test('emit error on sass errors when using sync true', function (t) {
|
||||
var stream = gsass({sync: true});
|
||||
var errorFile = createVinyl('somefile.sass',
|
||||
new Buffer('body { font \'Comic Sans\'; }'));
|
||||
stream.on('error', function (err) {
|
||||
t.equal(err.message,
|
||||
'source string:1: error: property "font" must be followed by a \':\'\n'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
stream.write(errorFile);
|
||||
});
|
||||
|
||||
test('call custom error callback when opts.onError is given', function (t) {
|
||||
var stream = gsass({ onError: function (err) {
|
||||
t.equal(err,
|
||||
|
|
Loading…
Reference in New Issue