PlayFramework: adding assets on compiling

Viewed 40

in our Scala project we're using Play Framework with some static assets in the public directory, linked in the normal way:

  • via "routes":

    GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

  • and in the "index.scala.hml":

    <script type="text/javascript" src="@routes.Assets.versioned("javascripts/main.js")">

Now we want to use a submodule written in nodejs, which should create other js files on compiling, and put them to the assets folder. We were able to run npm commands in the "build.sbt" file:

buildSubmodules := {
    val s: TaskStreams = streams.value
    val shell: Seq[String] = if (sys.props("os.name").contains("Windows")) Seq("cmd", "/c") else Seq("bash", "-c")
    val npmInstall: Seq[String] = shell :+ "npm --prefix submodules/ install"
    val npmBuild: Seq[String] = shell :+   "npm --prefix submodules/ run build"
    s.log.info("building submodules...")
    if((npmInstall #&& npmBuild !) == 0) {
    s.log.success("submodules build successful!")
    } else {
    throw new IllegalStateException("submodules build failed!")
    }
}
(Compile / compile) := ((Compile / compile) dependsOn buildSubmodules).value

and also included in the "index.scala.html":

<link rel="stylesheet" href="@routes.Assets.versioned("submodules/main.css")" />

but new created files still cannot be found in the "public/assets" folder after compilation finished. Is there any way to add these assets to compiled project?

Thank you

0 Answers
Related