From d4ed8ad2407e5094e902b44dc309258a97499b34 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 17 Mar 2019 08:15:52 +0000 Subject: [PATCH] Watch inlined files --- core/src/main.js | 16 +++++++++++----- tests/ext/themes/Example/index.scss | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main.js b/core/src/main.js index 46441e16b..edb1e739d 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -87,7 +87,7 @@ class Comms { }); }); - const sassImporter = async (context, url, prev) => { + const sassImporter = async (context, url, prev, inlinedFiles) => { let file = path.resolve(path.dirname(prev), url); const scss = await FileUtils.readFile(file).catch(err => FileUtils.readFile(file += '.scss')); @@ -95,7 +95,10 @@ class Comms { const result = await postcss([postcssUrl({url: 'inline', encodeType: 'base64', optimizeSvgEncode: true})]) .process(scss, {from: file, syntax: postcssScss}); - console.log('Processed', file, result); + for (const message of result.messages) { + if (message.type !== 'dependency') continue; + inlinedFiles.push(message.file); + } return {file, contents: result.css}; }; @@ -106,13 +109,16 @@ class Comms { options.path = undefined; } + const inlinedFiles = []; + options.importer = function (url, prev, done) { - sassImporter(this, url, prev).then(done, done); + sassImporter(this, url, prev, inlinedFiles).then(done, done); }; sass.render(options, (err, result) => { - if (err) event.reject(err); - else event.reply(result); + if (err) return event.reject(err); + result.stats.includedFiles = result.stats.includedFiles.concat(inlinedFiles); + event.reply(result); }); }); diff --git a/tests/ext/themes/Example/index.scss b/tests/ext/themes/Example/index.scss index 225229aae..36c9942d2 100644 --- a/tests/ext/themes/Example/index.scss +++ b/tests/ext/themes/Example/index.scss @@ -35,3 +35,7 @@ $index: 0; $index: $index + 1; } + +.bd-scroller { + background-image: url('icon.svg'); +}