cnmuc
cnmuc

Reputation: 6145

Speed up Javascript uglification in Play 2.3.x build for external Webjar sources

I'm using Play framework 2.3.6 and Webjars for web lib dependencies. That is, my build.sbt contains something like "org.webjars" % "angularjs" % "1.2.26". To uglify my Javascript sources I added pipelineStages := Seq(rjs, uglify, digest, gzip) to my build.sbt.

Now, when running Play's 'stage' or 'dist' tasks it looks like all Javascript files getting uglified, that is, also files from the Webjar libraries.
[info] Uglify2 file: /target/web/rjs/build/lib/angularjs/angular.js

I would have expected that sources from the external Webjar libraries are left untouched as there already is a minified version. One problem with that is that the uglify process takes way too long. How can I speed up the uglification process?

Upvotes: 3

Views: 1235

Answers (2)

Dadje
Dadje

Reputation: 149

Even though that the sbt-uglify documentation says that excludeFilter should exclude webjars and public folder, it doesn't.

Follow Martin's reponse customization part, except that he maid y typo, add an S to RjsKeys:

RjsKeys.optimize := "none"

Upvotes: 1

Martin Weindel
Martin Weindel

Reputation: 316

There are two ways to speed up the Javascript building steps:

  • Install node.js and set export SBT_OPTS="$SBT_OPTS -Dsbt.jse.engineType=Node" before running the activator. Using node.js instead of the default Javascript engine gives a very significant speedup. More details can be found here: Migration to play 2.3, see section about sbt-web

  • Customize the build steps, e.g.

    • disable minification by adding to build.sbt: RjsKey.optimize := "none"
    • limit uglification by adding to build.sbt: e.g. includeFilter in uglify := GlobFilter("myjs/*.js"),

You can find more details about the options on the github site of these plugins:

sbt-uglify

sbt-rjs

Upvotes: 1

Related Questions