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
.scss
files 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 ofthemes
you can maketheme_foo
andtheme_bar
call different tasks (e.g.:sass:theme_foo
orsass:theme_bar
) and then recompile just that theme.You can also run
grunt watch
on a specific task:grunt watch theme_foo
, which won't updatetheme_bar
but justtheme_foo
.Edit: You can modularize your
_main.scss
so it becomes_foo.scss
,_bar.scss
and_common.scss
, and then change_common.scss
when it's a change that affects all themes, and_foo.scss
when it just affectstheme_foo
. This way you can monitor_foo.scss
and update onlytheme_foo
when it changes; or update all your themes just when_common.scss
changes.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 sass
it will update both themes. But if you rungrunt sass red
it will update just the red theme.To make your
watch
update just the required theme, you'll have two tasks:Notice
red
callssass:red
(the task for that theme and only that theme). Same happens withblue
callingsass:blue
.To make it update every theme when
_main.scss
changes, you add one more task insidewatch
:Now
all
is watching your_main.scss
, and when it changes every task insass
will be run (i.e.sass:red
andsass:blue
).