2016-01-02 19 views

cevap

28

Uygulamanızı paketlediğinizde, dist ve stage bağımlılıklarının kullanıldığı bir özel sbt görevi tanımlayarak çalışmayı başardım.

görevin kod basittir: Webpack ile

PlayKeys.playRunHooks <+= baseDirectory.map(Webpack.apply) 

olarak tanımlanan aşağıdaki gibidir:: dev modunda

lazy val webpack = taskKey[Unit]("Run webpack when packaging the application") 

    def runWebpack(file: File) = { 
    Process("webpack", file) ! 
    } 

    webpack := { 
    if(runWebpack(baseDirectory.value) != 0) throw new Exception("Something goes wrong when running webpack.") 
    } 

    dist <<= dist dependsOn webpack 

    stage <<= stage dependsOn webpack 

ben kod değişiklikleri olduğunda webpack watch çalıştırmak için play action hooks kullanmak

import java.net.InetSocketAddress 
import play.sbt.PlayRunHook 
import sbt._ 

object Webpack { 
    def apply(base: File): PlayRunHook = { 
    object WebpackHook extends PlayRunHook { 
     var process: Option[Process] = None 

     override def beforeStarted() = { 
     process = Option(
      Process("webpack", base).run() 
     ) 
     } 

     override def afterStarted(addr: InetSocketAddress) = { 
     process = Option(
      Process("webpack --watch", base).run() 
     ) 
     } 

     override def afterStopped() = { 
     process.foreach(_.destroy()) 
     process = None 
     } 
    } 

    WebpackHook 
    } 
} 

Bir çekicilik gibi çalışır. Bu tekniği kullanarak örnek bir oyun projesi hesabımdan github bulmak: umarım bu yardımcı olur https://github.com/nouhoum/play-react-webpack/blob/master/webpack.sbt

;-)

1
Ben SBT 1.0.x

Sadece birkaç güncellendi kadar Nouhoum cevabı gayet çalışıyordu

güncellemeler gerekliydi:

import scala.sys.process.Process 

lazy val webpack = taskKey[Unit]("Run webpack when packaging the application") 

def runWebpack(file: File) = { 
    Process("npm run build", file) ! 
} 

webpack := { 
    if(runWebpack(baseDirectory.value) != 0) throw new Exception("Something went wrong when running webpack.") 
} 

dist := (dist dependsOn webpack).value 

stage := (stage dependsOn webpack).value 
İlgili konular