Play framework reads assets file in unmanagedResourceDirectories

380 views Asked by At

enter image description here I ran into a problem of reading a file in unmanagedResourceDirectories generated by Webpack in production mode. Given the following snippet:

  val manifest: Try[JsValue] = Try(Json.parse(
    Source.fromFile(new File("/public/manifest.json")).getLines.mkString
  ))

I want to read sth like /public/manifest.json.

1

There are 1 answers

0
Hung Phan On

I manage to find the solution for it. Add this to build.sbt

unmanagedResourceDirectories in Assets += (baseDirectory.value / "js-frontend" / "build"),
mappings in Universal ++= directory(baseDirectory.value / "js-frontend" / "build" / "manifest.json"),

And I can have sth like this in code:

val manifest: Try[JsValue] = Try(Json.parse(
  Source.fromFile(env.getFile("/manifest.json")).getLines.mkString
))