Search code examples
scalasbtsbt-web

How do I get sbt-web working in Build.scala?


I have a fairly complex project -- it's using Play, Scala.js and various other toys. It's built in Build.scala for the time being, because I haven't managed to get all the parts working in build.sbt yet. (I've talked about this separately on the sbt mailing list.)

Now, I'd like to take advantage of Play's new fingerprinting goodies, which means starting to play with sbt-web. I'm clearly doing something wrong, though. I've added the usual pipeline plugins to my plugins.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")

But when I tried to add SbtWeb to the JVM side of my project:

lazy val scalajvm = Project(
  id = "scalajvm",
  base = file("scalajvm")
) enablePlugins (play.PlayScala, SbtWeb) settings (scalajvmSettings: _*) aggregate (scalajs)

sbt complained that it didn't know SbtWeb, and wouldn't load. Odd. I added an explicit import:

import com.typesafe.sbt.web.SbtWeb

That allowed that to load. Then, I tried to get the pipeline itself working:

pipelineStages := Seq(digest, gzip),

Now it complained that it didn't know pipelineStages. Again, I added an explicit import, although suspecting that I'm doing something wrong:

import com.typesafe.sbt.web.Import.pipelineStages

That gets me to the next step: it's complaining that it doesn't know about digest -- which is completely mysterious, since I've got it specified right there in my plugins.sbt.

Any suggestions? My guess is that I'm missing something at the plugins level, but I have no clue what it is. All the documentation I can find just lists the above, but I think it's all assuming build.sbt. (Yes, I have sbt 0.13.5 specified in my build.properties, and Play 2.3.5 in my plugins.sbt.)


Solution

  • I use sbt-web from my Build.scala in my project too. You will need the following imports:

     import com.typesafe.sbt.digest.Import._
     import com.typesafe.sbt.gzip.Import._
     import com.typesafe.sbt.rjs.Import._
     import com.typesafe.sbt.web.Import._
    

    Each of the pipeline objects (values of type TaskKey[Pipeline.Stage]) comes from the Import object of the corresponding module. Why it is structured like this I'm not sure. I remember having the same wonderment about the includes needed for this when I first got this working too. I think it is structured that way in part to support the auto-plugin feature of sbt.