From eedc9c9eb1f07fa9c33a47149b80aa2f954dfb8b Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Sun, 10 Jul 2022 11:35:48 +0200 Subject: [PATCH] fix(webpack): remove copy rules that don't match any files to avoid false watch triggers --- packages/webpack5/src/helpers/copyRules.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/webpack5/src/helpers/copyRules.ts b/packages/webpack5/src/helpers/copyRules.ts index fe6dc932c..710e7ce4a 100644 --- a/packages/webpack5/src/helpers/copyRules.ts +++ b/packages/webpack5/src/helpers/copyRules.ts @@ -1,6 +1,7 @@ import CopyWebpackPlugin from 'copy-webpack-plugin'; import { basename, relative, resolve } from 'path'; import Config from 'webpack-chain'; +import { sync as globbySync } from 'globby'; import { getProjectRootPath } from './project'; import { getEntryDirPath } from './platform'; @@ -70,6 +71,15 @@ export function applyCopyRules(config: Config) { config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [ { patterns: Array.from(copyRules) + .filter((glob) => { + if (process.env.NODE_ENV === 'test') { + return true; + } + // remove rules that do not match any paths + // prevents webpack watch mode from firing + // due to "removed" paths. + return globbySync(glob).length > 0; + }) .map((glob) => ({ from: glob, context: entryDir,