File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 8
8
"squish/internal/utils"
9
9
"squish/pkg/esbuild"
10
10
"syscall"
11
+ "time"
11
12
)
12
13
13
14
type Watcher struct {
@@ -29,6 +30,9 @@ func (w *Watcher) Watch() error {
29
30
}
30
31
defer watcher .Close ()
31
32
33
+ var rebuildTimer * time.Timer
34
+ debounceDuration := 100 * time .Millisecond
35
+
32
36
done := make (chan bool )
33
37
go func () {
34
38
for {
@@ -38,10 +42,15 @@ func (w *Watcher) Watch() error {
38
42
return
39
43
}
40
44
if event .Op & fsnotify .Write == fsnotify .Write {
41
- utils .Log ("Modified file:" , event .Name )
42
- if err := w .bundler .Bundle (); err != nil {
43
- utils .Log ("Error bundling:" , err )
45
+ if rebuildTimer != nil {
46
+ rebuildTimer .Stop ()
44
47
}
48
+ rebuildTimer = time .AfterFunc (debounceDuration , func () {
49
+ utils .Log ("Detected changes, rebuilding..." )
50
+ if err := w .bundler .Bundle (); err != nil {
51
+ utils .Log ("Error bundling:" , err )
52
+ }
53
+ })
45
54
}
46
55
case err , ok := <- watcher .Errors :
47
56
if ! ok {
You can’t perform that action at this time.
0 commit comments