fix(sass): Watch included files as well

This commit is contained in:
Suraj Shetty 2022-03-14 15:48:54 +05:30 committed by GitHub
parent f8c4ce7453
commit fcd209b5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,6 +108,7 @@ const postCSSPlugin = ({
? fileIsModule(sourceFullPath) ? fileIsModule(sourceFullPath)
: sourceBaseName.match(/\.module$/); : sourceBaseName.match(/\.module$/);
const sourceDir = path.dirname(sourceFullPath); const sourceDir = path.dirname(sourceFullPath);
const watchFiles = [sourceFullPath];
let tmpFilePath: string; let tmpFilePath: string;
if (args.kind === "entry-point") { if (args.kind === "entry-point") {
@ -142,10 +143,11 @@ const postCSSPlugin = ({
let css = sourceExt === ".css" ? fileContent : ""; let css = sourceExt === ".css" ? fileContent : "";
// parse files with preprocessors // parse files with preprocessors
if (sourceExt === ".sass" || sourceExt === ".scss") if (sourceExt === ".sass" || sourceExt === ".scss") {
css = ( const sassResult = await renderSass({...sassOptions, file: sourceFullPath})
await renderSass({ ...sassOptions, file: sourceFullPath }) css = sassResult.css.toString();
).css.toString(); watchFiles.push(...sassResult.stats.includedFiles);
}
if (sourceExt === ".styl") if (sourceExt === ".styl")
css = await renderStylus(new TextDecoder().decode(fileContent), { css = await renderStylus(new TextDecoder().decode(fileContent), {
...stylusOptions, ...stylusOptions,
@ -167,6 +169,7 @@ const postCSSPlugin = ({
from: sourceFullPath, from: sourceFullPath,
to: tmpFilePath to: tmpFilePath
}); });
watchFiles.push(...getPostCssDependencies(result.messages));
// Write result CSS // Write result CSS
if (writeToFile) { if (writeToFile) {
@ -180,9 +183,7 @@ const postCSSPlugin = ({
? "file" ? "file"
: "postcss-text", : "postcss-text",
path: tmpFilePath, path: tmpFilePath,
watchFiles: [result.opts.from].concat( watchFiles,
getPostCssDependencies(result.messages)
),
pluginData: { pluginData: {
originalPath: sourceFullPath, originalPath: sourceFullPath,
css: result.css css: result.css