npm 'sass' package compile empty file in watch mode

Viewed 98

I use the npm sass library to compile my ".scss" file and it works really well without any problem but in watch mode, after some file save it starts to produce an empty file. I restart the app and it compiles successfully again. my watch file is at this link: sass builder file I don't know if this is my watcher problem or sass problem or even windows file system problem. can anyone check to help me to fix this problem?

1 Answers

I try many ways to fix this issue and I found the problem is the Windows file system. in the windows file system if I save a file for a short moment depend on your system performance the file get empty and refill again so to fix this issue I add the setTimeout function in watch mode about 500ms so when user save scss file and we detect change first we wait 500ms then execute build function.

//before
 if (fileName && event == "change") {
   this.buildSassFile(fileConfig);            
 }
//after
 if (fileName && event == "change") {
   setTimeout(()=>{
     this.buildSassFile(fileConfig);
   },300);
                
 }
Related