playframeworksbtplayframework-2.3uglifyjssbt-web

Different sbt-web pipeline task settings in development vs production?


I would like an sbt setting to have a different value when running in development (sbt run) than production (sbt dist / sbt start).

Specifically I am using sbt-uglify. I use it in development to concatenate javascript assets into one file. I have compression and mangling disabled in development because it makes code more difficult to debug.

In production I would like to use compression in order to remove blocks of debug code (if (DEBUG) { ... }) which is possible using the dead code removal features of uglifyjs.

I expected this to work:

// "in Assets" to use uglify in dev & prod
pipelineStages in Assets := Seq(uglify)

// enable compression and mangling in prod
UglifyKeys.compress := true
UglifyKeys.mangle := true

// disable in development (DOESN'T WORK! Values are always true)
UglifyKeys.compress in Assets := false
UglifyKeys.mangle in Assets := false

Solution

  • I ended up doing something like this

    def optimize = System.getProperty("optimize") != null
    
    UglifyKeys.compress := optimize
    UglifyKeys.mangle := optimize
    

    Then I can run sbt dist -J-Doptimize