-
Notifications
You must be signed in to change notification settings - Fork 14
/
watcher.ts
42 lines (34 loc) · 849 Bytes
/
watcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* eslint-disable no-console */
import chokidar from 'chokidar';
import runBuild from './builder.ts';
const watch = () => {
// Initial build
runBuild()
.then(() => {})
.catch(() => {});
// Watch directories
const watcher = chokidar.watch(['src/', 'public/'], {
ignored: /node_modules/,
persistent: true,
});
watcher.on('change', () => {
// console.log(`File ${path} has been changed`);
runBuild()
.then(() => {})
.catch(() => {});
});
watcher.on('add', () => {
// console.log(`File ${path} has been added`);
runBuild()
.then(() => {})
.catch(() => {});
});
watcher.on('unlink', () => {
// console.log(`File ${path} has been removed`);
runBuild()
.then(() => {})
.catch(() => {});
});
console.log('Watching for file changes...');
};
watch();