diff --git a/index.js b/index.js index b4d901c3..8102df2a 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var sass = require('node-sass'); var path = require('path'); var os = require('os'); var fs = require('fs'); +var async = require('async'); // A typical sass error looks like this var SassError = { @@ -16,6 +17,12 @@ var SassError = { }; var resolveError = /Cannot resolve/; +// This queue makes sure node-sass leaves one thread available for executing +// fs tasks when running the custom importer code. +// This can be removed as soon as node-sass implements a fix for this. +var threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4; +var asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1); + /** * The sass-loader makes node-sass available to webpack modules. * @@ -155,7 +162,8 @@ module.exports = function (content) { throw err; } } - sass.render(opt, function onRender(err, result) { + + asyncSassJobQueue.push(opt, function onRender(err, result) { if (err) { formatSassError(err); callback(err); diff --git a/package.json b/package.json index 7cd92118..d20c27f2 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "node-sass": "^3.1.0" }, "dependencies": { + "async": "^1.4.0", "loader-utils": "^0.2.5" }, "devDependencies": {