Skip to content

Commit

Permalink
Fix: Watcher for sass files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Jul 27, 2021
1 parent f5f6a11 commit 0435f3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Lib/sass.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function render(key) {
sourceMapContents: true,
sourceMapEmbed: true,
});
return result.css?.toString();
const css = result.css.toString();
const importedFiles = [...result.stats.includedFiles].filter((file) => file != key);
return { css, importedFiles };
}

export { render };
21 changes: 20 additions & 1 deletion postcss.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ function renderFiles(keys) {
print(cyan(`Processing ${bold(file.from)}...`));

if (file.sass) {
content = sassFunction.render(key);
const result = sassFunction.render(key);
files[key].importedFiles = result.importedFiles;
content = result.css;
}
return css(content, file, time);
});
Expand All @@ -54,6 +56,15 @@ function build() {
pollInterval: 10,
},
});

// Add files from sass
const importedFiles = files[input].importedFiles;
let importedFilesLength = importedFiles?.length || 0;

if (importedFilesLength) {
watcher.add(importedFiles);
}

if (configFile) {
watcher.add(configFile);
}
Expand All @@ -69,6 +80,14 @@ function build() {
if (!recompile.length) {
recompile = input;
}

// Add new files from sass
const importedFiles = files[input].importedFiles;
if (importedFilesLength < importedFiles?.length) {
importedFilesLength = importedFiles.length;
watcher.add(importedFiles);
}

return renderFiles([...new Set(recompile)])
.then((results) => watcher.add(dependencies(results)))
.then(printMessage)
Expand Down

0 comments on commit 0435f3f

Please sign in to comment.