Skip to content

Commit ba2ae4a

Browse files
Merge branch 'tkow-fix/webpack-watch-assets'
2 parents 9cabe87 + dca312c commit ba2ae4a

3 files changed

Lines changed: 2514 additions & 2104 deletions

File tree

lib/compiler/assets-manager.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as chokidar from 'chokidar';
2+
import { statSync } from 'fs';
3+
import { sync } from 'glob';
24
import { dirname, join, sep } from 'path';
35
import * as shell from 'shelljs';
46
import {
@@ -89,14 +91,22 @@ export class AssetsManager {
8991
watchAssetsMode: isWatchEnabled,
9092
};
9193

92-
// prettier-ignore
93-
const watcher = chokidar
94-
.watch(item.glob, { ignored: item.exclude })
95-
.on('add', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
96-
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
97-
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));
94+
if (isWatchEnabled || item.watchAssets) {
95+
// prettier-ignore
96+
const watcher = chokidar
97+
.watch(item.glob, { ignored: item.exclude })
98+
.on('add', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
99+
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
100+
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));
98101

99-
this.watchers.push(watcher);
102+
this.watchers.push(watcher);
103+
} else {
104+
const files = sync(item.glob, { ignore: item.exclude })
105+
.filter((matched) => statSync(matched).isFile());
106+
for (const path of files) {
107+
this.actionOnFile({ ...option, path, action: 'change' });
108+
}
109+
}
100110
}
101111
} catch (err) {
102112
throw new Error(

0 commit comments

Comments
 (0)