From ab0da81394630e1a99578373e4178767d4b033a5 Mon Sep 17 00:00:00 2001 From: Lochlan Bunn Date: Mon, 26 Oct 2015 11:08:10 +1000 Subject: [PATCH] allow parallel bundles to isolate their css source caches --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 827907d..053e5e0 100644 --- a/index.js +++ b/index.js @@ -101,6 +101,11 @@ module.exports = function (browserify, options) { var cssOutFilename = options.output || options.o; var jsonOutFilename = options.json || options.jsonOutput; + var sourceKey = cssOutFilename; + + // keying our source caches by the name of our output file means we can + // isolate css compilation of seperate bundles that are running in parallel + sourceByFile[sourceKey] = sourceByFile[sourceKey] || {}; // PostCSS plugins passed to FileSystemLoader var plugins = options.use || options.u; @@ -166,7 +171,7 @@ module.exports = function (browserify, options) { assign(tokensByFile, loader.tokensByFile); // store this file's source to be written out to disk later - sourceByFile[filename] = loader.finalSource; + sourceByFile[sourceKey][filename] = loader.finalSource; compiledCssStream.push(loader.finalSource); @@ -190,8 +195,8 @@ module.exports = function (browserify, options) { bundle.emit('css stream', compiledCssStream); bundle.on('end', function () { - // Combine the collected sources into a single CSS file - var files = Object.keys(sourceByFile); + // Combine the collected sources for a single bundle into a single CSS file + var files = Object.keys(sourceByFile[sourceKey]); var css; // end the output stream @@ -200,7 +205,7 @@ module.exports = function (browserify, options) { // write the css file if (cssOutFilename) { css = files.map(function (file) { - return sourceByFile[file]; + return sourceByFile[sourceKey][file]; }).join('\n'); fs.writeFile(cssOutFilename, css, function (err) {