2
votes

I want to minify my self written javascripts in Play Framework 2.3.10. I started putting all my scripts to app/assets/javascripts/*. Additionally i added the following route in conf/routes:

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

I added the following lines to enable minification with uglify and digest. to plugins.sbt:

addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

and to build.sbt:

pipelineStages in Assets := Seq(uglify, digest)

Everything works like a charm. When i am requesting the website in my browser i see the minified javascript file (.min.js) and also the normal (source) javascript file (.js). The problem is that there is a source map generated and attached to the minified javascript. It links to the source file. How can i avoid that? Is it possible to hide / deny access to the source javascript files so that a user can just request the minified version ( even when trying to access the source file via direct url [ e.g. mypage.de/assets/v/javascripts/script.js ] ) ?

Thanks in advance, Rob

1

1 Answers

0
votes

Okay,

i found a solution for my problem. I added a filter to filter out all .js files in my app/assets/javascripts/ folder. I did this by adding

addSbtPlugin("com.slidingautonomy.sbt" % "sbt-filter" % "1.0.1")

to my project/plugins.sbt file. I changed the pipelineStages in the build.sbt to add a filter.

pipelineStages in Assets := Seq(uglify, digest, filter)

includeFilter in filter := new FileFilter {
  def accept(pathname: File): Boolean = {
    val path = pathname.getAbsolutePath.replaceAll("\\\\", "/")
    path.contains("javascripts/functions")
  }
}

excludeFilter in filter := "*.min.js"

Play is now creating all minified js.min files. After that all files in javascripts/functions are filtered except the min.js files. I hope this helps.

Rob