I was able to load the sbt-uglify 1.0.3 plugin in my Play Framework 2.3.1 app. Loading of the non-minified javascripts is pretty straightforward, but loading the minified versions seems to be impossible.
In my template I use <script>
tags similar to this:
<script src="@routes.Assets.at("javascripts/app.js")"></script>
In dev mode, the non-minified javascript version is loaded, which is fine. In prod mode (using activator start
) I see sbt-uglify generating the minified versions to the target/web/uglify/build
folder, but because I didn't change the above <script>
tag line in my templates, the non-minified versions of the javascripts files are loaded.
Is there a way to do a prod-only mapping of such routes to load the minified versions?
The issue Reverse Router should use minified assets in production automatically was fixed in Play 2.3.1 that exactly matches your requirement.
According to Play 2.3.1 Changelog:
NOTE It should rather read set
assets.checkForMinified=false
, but anyway...What follows works in production mode only so start the application with
activator start
notrun
or use the generated start scripts (afterstage
).The behaviour of using minified versions of assets in production should be enabled by default in the version of Play with
@routes.Assets.versioned
(notroutes.Assets.at
).It does require that the appropriate route declaration in
conf/routes
is:What I found a bit unclear at first was the order of elements in
pipelineStages
as well as the requirement to include sbt-rjs in it.And just after I'd written the sentence about the order I found in the section "RequireJS" in Play 2.3 Migration Guide:
I've also found in Play 2.3 Migration Guide in the section "Closure Compiler":
It all started with the answer to Play 2.3 sbt-web plugin Javascript minification.
So, the below
pipelineStages
is the working one - mind the order andrjs
:project/plugins.sbt
used was as follows:Don't forget to create an empty
app/assets/javascripts/main.js
file to letsbt-rjs
do its job.As a test, I created a Play application with
activator new playApp play-scala
and applied the above changes in the build as well as inapp/views/main.scala.html
that ultimately looked as follows (note@routes.Assets.versioned
):Executing
activator start
and callingcurl http://localhost:9000
gives (formatting's mine for the sake of readability):Note
4302136334616ae0605d47a1932ee262-hello.min.js
and the non-JavaScript resources digested.