Skip to content

Commit

Permalink
Watch inlined files
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelthomas2774 committed Mar 17, 2019
1 parent 6a38e8e commit d4ed8ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions core/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ 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'));

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};
};
Expand All @@ -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);
});
});

Expand Down
4 changes: 4 additions & 0 deletions tests/ext/themes/Example/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ $index: 0;

$index: $index + 1;
}

.bd-scroller {
background-image: url('icon.svg');
}

0 comments on commit d4ed8ad

Please sign in to comment.