Skip to content

Commit

Permalink
Merge branch 'tkow-fix/webpack-watch-assets'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 23, 2023
2 parents 9cabe87 + dca312c commit ba2ae4a
Show file tree
Hide file tree
Showing 3 changed files with 2,514 additions and 2,104 deletions.
24 changes: 17 additions & 7 deletions lib/compiler/assets-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as chokidar from 'chokidar';
import { statSync } from 'fs';
import { sync } from 'glob';
import { dirname, join, sep } from 'path';
import * as shell from 'shelljs';
import {
Expand Down Expand Up @@ -89,14 +91,22 @@ export class AssetsManager {
watchAssetsMode: isWatchEnabled,
};

// prettier-ignore
const watcher = chokidar
.watch(item.glob, { ignored: item.exclude })
.on('add', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));
if (isWatchEnabled || item.watchAssets) {
// prettier-ignore
const watcher = chokidar
.watch(item.glob, { ignored: item.exclude })
.on('add', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('change', (path: string) => this.actionOnFile({ ...option, path, action: 'change' }))
.on('unlink', (path: string) => this.actionOnFile({ ...option, path, action: 'unlink' }));

this.watchers.push(watcher);
this.watchers.push(watcher);
} else {
const files = sync(item.glob, { ignore: item.exclude })
.filter((matched) => statSync(matched).isFile());
for (const path of files) {
this.actionOnFile({ ...option, path, action: 'change' });
}
}
}
} catch (err) {
throw new Error(
Expand Down
Loading

0 comments on commit ba2ae4a

Please sign in to comment.