From fcd209b5fb1aaf92d320b0c8792ae506c2eb08c8 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Mon, 14 Mar 2022 15:48:54 +0530 Subject: [PATCH] fix(sass): Watch included files as well --- src/index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1bf85ba..ff0a795 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,6 +108,7 @@ const postCSSPlugin = ({ ? fileIsModule(sourceFullPath) : sourceBaseName.match(/\.module$/); const sourceDir = path.dirname(sourceFullPath); + const watchFiles = [sourceFullPath]; let tmpFilePath: string; if (args.kind === "entry-point") { @@ -142,10 +143,11 @@ const postCSSPlugin = ({ let css = sourceExt === ".css" ? fileContent : ""; // parse files with preprocessors - if (sourceExt === ".sass" || sourceExt === ".scss") - css = ( - await renderSass({ ...sassOptions, file: sourceFullPath }) - ).css.toString(); + if (sourceExt === ".sass" || sourceExt === ".scss") { + const sassResult = await renderSass({...sassOptions, file: sourceFullPath}) + css = sassResult.css.toString(); + watchFiles.push(...sassResult.stats.includedFiles); + } if (sourceExt === ".styl") css = await renderStylus(new TextDecoder().decode(fileContent), { ...stylusOptions, @@ -167,6 +169,7 @@ const postCSSPlugin = ({ from: sourceFullPath, to: tmpFilePath }); + watchFiles.push(...getPostCssDependencies(result.messages)); // Write result CSS if (writeToFile) { @@ -180,9 +183,7 @@ const postCSSPlugin = ({ ? "file" : "postcss-text", path: tmpFilePath, - watchFiles: [result.opts.from].concat( - getPostCssDependencies(result.messages) - ), + watchFiles, pluginData: { originalPath: sourceFullPath, css: result.css