I'm trying to work my way through the updates to Visual Studio 2015 including using Grunt and so on.
I can get Grunt to recompile .scss files when they change, but I have a problem. I use SASS for theming, and a lot of my CSS is in a central _main.scss. What I want is when I edit that file, it should recompile all the theme-*.scss files that include _main.scss.
Is there any way to tell watch or stuff like that to recompile things when dependencies change? Even if I have to specify the dependencies manually?
I don't know if there's a way to follow dependencies from one file to another, but you can watch for changes in
.scssfiles and then run a sass task to update your theme files.So you'll have your sass task like this:
And then your watch task like this:
The downside of this is that all your themes will compile each time you change your
_main.scss. If you have different files to watch for different themes then you can have more tasks insidewatch(instead ofthemesyou can maketheme_fooandtheme_barcall different tasks (e.g.:sass:theme_fooorsass:theme_bar) and then recompile just that theme.You can also run
grunt watchon a specific task:grunt watch theme_foo, which won't updatetheme_barbut justtheme_foo.Edit: You can modularize your
_main.scssso it becomes_foo.scss,_bar.scssand_common.scss, and then change_common.scsswhen it's a change that affects all themes, and_foo.scsswhen it just affectstheme_foo. This way you can monitor_foo.scssand update onlytheme_foowhen it changes; or update all your themes just when_common.scsschanges.Edit 2 (based on comments):
Lets say we have two themes, blue and red. We'll have two sass tasks (one for each theme):
Right now, if you run
grunt sassit will update both themes. But if you rungrunt sass redit will update just the red theme.To make your
watchupdate just the required theme, you'll have two tasks:Notice
redcallssass:red(the task for that theme and only that theme). Same happens withbluecallingsass:blue.To make it update every theme when
_main.scsschanges, you add one more task insidewatch:Now
allis watching your_main.scss, and when it changes every task insasswill be run (i.e.sass:redandsass:blue).