0

I have a scenario where I only run a task (minify js) if two files are different. If they're the same, then I don't need to run.

Best way would be to first compare sizes, if they are different then the files are too. If they are the same, then compare contents and then decide if to run the task or not.

Can't seem to figure out a way to do it.

oshkosh
  • 551
  • 7
  • 14
  • Possible duplicate of [How to run a task ONLY on modified file with Gulp watch](http://stackoverflow.com/questions/23890806/how-to-run-a-task-only-on-modified-file-with-gulp-watch) – Sven Schoenung Dec 16 '16 at 16:13
  • 1
    @SvenSchoenung I am actually looking for a straight up diff. I will ALWAYS create a new file (using webpack). If the resulting file is the same as the old one, I don't minify it and just use the old minified version. If they are different, I minify the new file and replace the old minified with the new one. – oshkosh Dec 16 '16 at 16:20
  • This totally sounds like a task for [gulp-cached](https://github.com/contra/gulp-cached), as suggested in the answer to the linked question. Or maybe I misunderstand. – SáT Dec 16 '16 at 16:30
  • @SáT I looked into it, but won't work if the server restarts since it's in-memory. – oshkosh Dec 16 '16 at 16:33
  • 1
    Then use `gulp-cache` or `gulp-changed`. – Sven Schoenung Dec 16 '16 at 16:34
  • @SvenSchoenung That worked. I didn't know there was an option to gulp watch files! Still not quite there since I need to "watch" and can't be a standalone process, but it's good enough for now. Thanks for the help – oshkosh Dec 16 '16 at 17:26

0 Answers0