I've probably got a bug in my code, as I'm really new to using Grunt.

I'm using compass on my local macbook, and also uglify with Grunt. I followed this guide: http://matthew-jackson.com/notes/development/grunt-workflow-for-sass-compass-and-js/

I've managed to get it working fine, but when I make a change in my JS file it shows as running multiple times, and therefore a simple 'alert' box test in my js file is compiled several times (about 10) into my min.js file, it should only do it once of course!

Why is it doing this?

Here is my gruntfile: https://github.com/Tjobbe/sample-grunt-project/blob/master/gruntfile.js and my package.json file: https://github.com/Tjobbe/sample-grunt-project/blob/master/package.json

Anything else you might want is here: https://github.com/Tjobbe/sample-grunt-project

有帮助吗?

解决方案

Looking at your Gruntfile I noticed this is the flow:

  1. At first uglify is run.
  2. Watch plugin looks for changes
  3. You save a watched js file
  4. Change is detected
  5. The watched file is minified into the watched directory → back to step 4.

Step 5 causes an infinite loop. Apparently this results into what you just described. In other words: You shouldn't save the minified file to the watched directory.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top