From fb0d9eac15f211e5922c02dac095014d2cb5f34f Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Mon, 14 Mar 2022 14:51:14 +0530 Subject: [PATCH] fix(sass): Watch included files as well --- src/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1b4f034..f357d51 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,6 +87,7 @@ const postCSSPlugin = ({ const sourceRelDir = path.relative(path.dirname(rootDir), sourceDir); const isModule = sourceBaseName.match(/\.module$/); const tmpDir = path.resolve(tmpDirPath, sourceRelDir); + const watchFiles = [sourceFullPath]; let tmpFilePath = path.resolve( tmpDir, @@ -103,10 +104,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") { + let result = await renderSass({ ...sassOptions, file: sourceFullPath }) + css = result.css.toString(); + watchFiles.push(...result.stats.includedFiles); + } if (sourceExt === ".styl") css = await renderStylus(new TextDecoder().decode(fileContent), { ...stylusOptions, @@ -135,7 +137,7 @@ const postCSSPlugin = ({ return { namespace: isModule ? "postcss-module" : "file", path: tmpFilePath, - watchFiles: [sourceFullPath], + watchFiles, pluginData: { originalPath: sourceFullPath }