fix(webpack): remove copy rules that don't match any files to avoid false watch triggers

This commit is contained in:
Igor Randjelovic
2022-07-10 11:35:48 +02:00
committed by Nathan Walker
parent fefac9f554
commit eedc9c9eb1

View File

@ -1,6 +1,7 @@
import CopyWebpackPlugin from 'copy-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin';
import { basename, relative, resolve } from 'path'; import { basename, relative, resolve } from 'path';
import Config from 'webpack-chain'; import Config from 'webpack-chain';
import { sync as globbySync } from 'globby';
import { getProjectRootPath } from './project'; import { getProjectRootPath } from './project';
import { getEntryDirPath } from './platform'; import { getEntryDirPath } from './platform';
@ -70,6 +71,15 @@ export function applyCopyRules(config: Config) {
config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [ config.plugin('CopyWebpackPlugin').use(CopyWebpackPlugin, [
{ {
patterns: Array.from(copyRules) 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) => ({ .map((glob) => ({
from: glob, from: glob,
context: entryDir, context: entryDir,