Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit f176721

Browse files
committed
Merge pull request webpack-contrib#132 from jorrit/async
Introduce a queue such that a Node thread is available for fs tasks
2 parents 8f7afc1 + 19a54ce commit f176721

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var sass = require('node-sass');
55
var path = require('path');
66
var os = require('os');
77
var fs = require('fs');
8+
var async = require('async');
89

910
// A typical sass error looks like this
1011
var SassError = {
@@ -19,6 +20,12 @@ var SassError = {
1920
var extPrecedence = ['.scss', '.sass', '.css'];
2021
var matchCss = /\.css$/;
2122

23+
// This queue makes sure node-sass leaves one thread available for executing
24+
// fs tasks when running the custom importer code.
25+
// This can be removed as soon as node-sass implements a fix for this.
26+
var threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4;
27+
var asyncSassJobQueue = async.queue(sass.render, threadPoolSize - 1);
28+
2229
/**
2330
* The sass-loader makes node-sass available to webpack modules.
2431
*
@@ -232,7 +239,8 @@ module.exports = function (content) {
232239
throw err;
233240
}
234241
}
235-
sass.render(opt, function onRender(err, result) {
242+
243+
asyncSassJobQueue.push(opt, function onRender(err, result) {
236244
if (err) {
237245
formatSassError(err);
238246
err.file && self.dependency(err.file);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"node-sass": "^3.2.0"
3131
},
3232
"dependencies": {
33+
"async": "^1.4.0",
3334
"loader-utils": "^0.2.5"
3435
},
3536
"devDependencies": {

0 commit comments

Comments
 (0)