|
1 | 1 | import * as chokidar from 'chokidar'; |
| 2 | +import { statSync } from 'fs'; |
| 3 | +import { sync } from 'glob'; |
2 | 4 | import { dirname, join, sep } from 'path'; |
3 | 5 | import * as shell from 'shelljs'; |
4 | 6 | import { |
@@ -89,14 +91,22 @@ export class AssetsManager { |
89 | 91 | watchAssetsMode: isWatchEnabled, |
90 | 92 | }; |
91 | 93 |
|
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' })); |
98 | 101 |
|
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 | + } |
100 | 110 | } |
101 | 111 | } catch (err) { |
102 | 112 | throw new Error( |
|
0 commit comments