Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT task preceding compilation doesn't get executed in triggered compilation

In this post I figured I will learn about sbt tasks and create on of my own. I've reached a stage where I've created a task that runs before compilation and compiles my sass.

val sassCompile = TaskKey[ Unit ]( "sassCompile" )

sassCompile := { 
  SassCompiler.compile( baseDirectory.value )
}

watchSources <++= baseDirectory map { path => ((path / "app" / "assets" ) ** "*.scss").get }

compile <<= (compile in Compile) dependsOn sassCompile

I do two things:

  1. Ensure that every change to scss triggers compilation
  2. Before compilation, sass compiler runs

So what works:

  1. Triggered compilation works. Every time I change my scala, compilation triggers. (Usual behaviour). Every time I change .scss inside the mentioned path: app/assets/**, compilation triggers. Everything fine.
  2. When I manually type compile on the play console, the sass compilation also triggers and I can see the css file change.

What doesn't work:

When compilation is triggered automatically (by virtue of calling ~compile or ~run and then making a change (or even not making a change), sass compilation does not get called. So when I do play ~run, my sass compiler doesn't get invoked.

EDIT: If it helps, here is a similar question.

like image 942
0fnt Avatar asked Nov 05 '14 18:11

0fnt


1 Answers

You need to change the last line to:

compile in Compile <<= (compile in Compile) dependsOn sassCompile

Explanation to this you can find here in "When to specify a scope" section.

like image 172
rtruszk Avatar answered Oct 28 '22 02:10

rtruszk