Skip to content

Commit

Permalink
Fix watching entry CSS file
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderby committed Sep 24, 2023
1 parent 448b026 commit cdc057c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tasks/bundle-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,22 @@ async function bundleCSS({platforms, debug}) {
}
}

/**
* @param {CSSEntry} entry
* @returns {string}
*/
function getEntryFile(entry) {
return rootPath(entry.src);
}

function getWatchFiles() {
const watchFiles = new Set();
cssEntries.forEach((entry) => {
entry.watchFiles?.forEach((file) => watchFiles.add(file));
const entryFile = getEntryFile(entry);
if (!watchFiles.has(entryFile)) {
watchFiles.add(entryFile);
}
});
return Array.from(watchFiles);
}
Expand All @@ -74,7 +86,12 @@ const bundleCSSTask = createTask(
return watchFiles;
},
async (changedFiles, watcher, platforms) => {
const entries = cssEntries.filter((entry) => changedFiles.some((changed) => entry.watchFiles?.includes(changed)));
const entries = cssEntries.filter((entry) => {
const entryFile = getEntryFile(entry);
return changedFiles.some((changed) => {
return entry.watchFiles?.includes(changed) || changed === entryFile;
});
});
for (const entry of entries) {
const css = await bundleCSSEntry(entry);
await writeFiles(entry.dest, platforms, true, css);
Expand Down

0 comments on commit cdc057c

Please sign in to comment.