我试图将gulp添加到我的Play应用程序中,我创建了一个PlayRunHook
对象,应该允许我触发gulp
命令,但是当我执行sbt run
时我收到一条错误消息,说找不到该对象。这是我的钩子:
package hooks
object Gulp extends CommandHook {
override def beforeStarted(): Unit = {
exec("gulp")
}
}
然后在build.sbt
:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.7"
scalacOptions ++= Seq("-deprecation")
libraryDependencies ++= Seq(
"junit" % "junit" % "4.10" % "test",
"org.reactivemongo" %% "play2-reactivemongo" % "0.11.14",
"com.typesafe.play" %% "play" % "2.5.0",
"com.typesafe.play" %% "play-netty-server" % "2.5.0"
)
PlayKeys.playRunHooks += hooks.Gulp()
但我明白了:
build.sbt:18: error: not found: value hooks
PlayKeys.playRunHooks += hooks.Gulp()
答案 0 :(得分:2)
您必须在 object
目录中创建Gulp project/
,如下所示:
import play.sbt.PlayRunHook
import sbt._
object Gulp {
def apply(base: File): PlayRunHook = {
object GulpProcess extends PlayRunHook {
override def beforeStarted(): Unit = {
Process("gulp", base).run
}
}
GulpProcess
}
}
然后在build.sbt
:
PlayKeys.playRunHooks += Gulp(baseDirectory.value)
有关详细信息,请查看此guide。
答案 1 :(得分:0)
编辑:我实际上最终接受了接受的答案,这个替代答案会在每次向您的应用发出请求时触发gulp bundle
命令。通过使用PlayRunHook
方法,您可以获得不同的生命周期钩子,最后我会挂钩beforeStarted
(如在接受的答案中所做的那样)以在启动应用时触发gulp watch
我可能会改变这一点,以便在开发时gulp watch
和gulp build
进行部署,但我尚未处于该阶段。
接受的答案解释了为什么build.sbt
无法找到值hooks
(代码需要位于目录project/
中),但要解决我想要运行{{1}的问题在编译期间,我选择了这个解决方案:
gulp bundle