diff --git a/tasks/uncss.js b/tasks/uncss.js index cb8eb98..d22ea58 100644 --- a/tasks/uncss.js +++ b/tasks/uncss.js @@ -19,6 +19,8 @@ module.exports = function (grunt) { report: 'min' }); + let fileInProcess = 0; + this.files.forEach(file => { const src = file.src.filter(filepath => { if (/^https?:\/\//.test(filepath)) { @@ -40,7 +42,13 @@ module.exports = function (grunt) { } try { + fileInProcess++; uncss(src, options, (error, output, report) => { + fileInProcess--; + if (fileInProcess === 0) { + done(); + } + if (error) { throw error; } @@ -51,8 +59,6 @@ module.exports = function (grunt) { if (typeof options.reportFile !== 'undefined' && options.reportFile.length > 0) { grunt.file.write(options.reportFile, JSON.stringify(report)); } - - done(); }); } catch (error) { const err = new Error('Uncss failed.');