I have a web-app whose directory structure looks like this:
src/
- styles/
- a.css
- b.css
- c.scss
- d.scss
- media/
- d.jpg
- e.png
- f.mpf
dest/
- css/
- media/
package.json
Gruntfile.js
I want to use the Gruntfile to watch files for changes. And when they change, process or copy them. I don't want files to be copied or processed unneccesarily. I'm trying to figure out how to do this with the Gruntfile and finding it pretty tricky.
I come from the world of C++ and makefiles. They were great because for each derived file, you would specify the command to derive it, and the files on which that derivation was directly dependent. If any of the dependency files were newer than the target, your command would be run. If any of the dependency files were absent, then it would be generated based on this same recursive logic.
How can I achieve the same thing here in Grunt? Specifying watches allows you to watch multiple files for changes. But then the command you run is usually not specific to the changed file.
My Gruntfile is here. Please show me how I can modify it to implement the following 3 rules:
- When any file src/styles/.scss changes, compile it with Sass and place the result in dest/css/.css. Then minify it to dest/css/*.min.css
- When any file src/styles/.css changes, copy it to dest/css/.css. Then minify it to dest/css/*.min.css
- When any file src/media/* changes, copy it to dest/media/*
I want these rules to be generic. IE: I don't want to have to write separate rules for b.scss
and d.scss
. It seems dumb to have to specify similar rules explicitly for every single file.