Grunt Imagemin on New Files - gruntjs

I'm using Grunt Imagemin to optimize a folder of images. However everytime I run that command, it runs imagemin on ALL of the images. Is there a way to only run grunt imagemin when it detects new changes?

Try implementing grunt-newer:
Grunt Task for running tasks if source files are newer only.
Here you can find a short tutorial about how to use it.
After implementing it, you should prepend newer: to the imagemin task.

Related

Compiling Stylus Files while scaffolding with Yeoman

I've got my own generators which work like charms.
One thing I'd like to add to them that would make my work faster is to compile stylus file once they have been copied to the new project folder. Is there a way to achieve this with Yeoman without the user being forced to launch grunt after the yo command?
Thank you!
Andrea
Can't you just have the compiled CSS in this case anyway? If the Yo process can install npm dependencies then you should be able to execute a script that will compile the stylus files.

Issue when I run "grunt build"

I am working with grunt and when I write "grunt build" my dist folder builds everything, except for the js files. I get the following message:
I'm guessing I have to edit my Gruntfile, but I'm not sure how to go about solving this.
My Gruntfile is long, but here is the uglify part:
What does it mean by the destination was not written because src files were empty
It means the files listed in dist: {src:"<%config.app%>*" were not created yet. Use the following process:
Run copy and uglify manually and verbosely
grunt copy:dist --verbose
grunt uglify:dist --verbose
If it works, reorganize the task in question in the registerTask method:
grunt registerTask("build", ['copy:dist','uglify:dist']);
Otherwise, dump the <%config.app%> path to make sure it is correct
grunt.registerTask('dump', 'Dump Output', function(){ console.log(grunt.config.get() ) });
References
Grunt API: grunt.config.get
Grunt Documentation: Using the CLI

How can I execute additional commands after changes detected by `compass watch`?

I've executed compass watch in a Zurb Foundation project.
It works great, my assets are compiled as I make settings changes.
However, I'd like to also run additional a few grunt commands each time I make changes.
How can I add to the actions that compass performs when changes are detected?
Specifically, I'd like to run two commands from another directory.
This is what I've got:
cd /dir_foundation/
bundle exec compasss watch
After each change, I want it to also call:
grunt sass:dist
grunt cssmin
These grunt tasks are defined in a gruntfile that is 2 directories "up" from the /dir_foundation/ where the compass watch command is monitoring changes.
I found an answer.
http://compass-style.org/help/documentation/configuration-reference/#callbacks
This is what I added to my config.rb file:
on_stylesheet_saved do |file|
system('../../../compile.bat')
end
Where "compile.bat" contains:
grunt sass:dist
grunt cssmin

Grunt concat includes a file that it should ignore; why is it ignoring Gruntfile.js?

I have a Grunt task to concat 3x JS files into a single plugins.js file. I now no longer require one of the files (let's call it unrequired.js), so I've removed it from the list of source files in Gruntfile.js. However, whenever I run grunt concat, the output file still contains unrequired.js. The only way around it is to trash unrequired.js and then run the task again. Is there some kind of caching feature at play here? Does the concat task ignore changes being made to Gruntfile? What am I missing?

How can I load two grunt tasks with the same name?

Im using yeoman for a project.
Basically it's working fine, but during the build process I want to move my images folder to somewhere else.
So I loaded the grunt-contrib-copy task which would let me do that. But unfortunately this conflicts with the yeoman built-in copy task.
Is there any way to alias the grunt-contrib-copy in my Gruntfile.js so I can use both of them?
grunt.loadNpmTasks('grunt-contrib-copy');
//Here I need to use "copy" again but not referencing the yeoman task but the grunt-contrib-copy task.
grunt.registerTask('build','intro clean coffee compass mkdirs concat css min replace copy time');
grunt.renameTask() will probably help you here. Try this:
// temporarily rename yeoman's copy task
grunt.renameTask('copy', 'yeomanCopy');
// load 'copy' from grunt-contrib-copy
grunt.loadNpmTasks('grunt-contrib-copy');
// rename it to something other than 'copy'
grunt.renameTask('copy', 'myCopy');
// rename yeoman's task back to its original name so nothing breaks
grunt.renameTask('yeomanCopy', 'copy');
// now use 'myCopy' for your purposes
// ...

Resources