15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PlayFramework 2.3でactivator run時にgulpを起動する

Posted at

PlayFramework2.3でactivator runしたときにgulpも起動する方法です。

元ネタはPlay Framework で開発用Webサーバと同時に grunt/gulp を起動する - はこべブログ ♨ですが、こちらの記事の方法では、Playの2.3からplay.Project.playScalaSettingsが無くなったので、うまく動きませんでした。

いろいろ調べてみたら、build.sbtでimport play.PlayImport.PlayKeys.playRunHooksしたら動きました。

build.sbt
name := """new-ui"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  ws,
  "jp.t2v" %% "play2-auth"      % "0.13.2",
  "jp.t2v" %% "play2-auth-test" % "0.13.2" % "test"
)

import play.PlayImport.PlayKeys.playRunHooks

playRunHooks += RunSubProcess("gulp watch")

project/RunSubProcess.scalaを作っておきます。

project/RunSubProcess.scala
import sbt._

import play.PlayRunHook

object RunSubProcess {
  def apply(command: String): PlayRunHook = {

    object RunSubProcessHook extends PlayRunHook {

      var process: Option[Process] = None

      override def beforeStarted(): Unit = {
        process = Some(Process(command).run)
      }

      override def afterStopped(): Unit = {
        process.map(p => p.destroy())
        process = None
      }
    }

    RunSubProcessHook
  }
}
15
14
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?