Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 537
dwickern Avatar asked May 13 '15 22:05

dwickern


1 Answers

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

like image 111
dwickern Avatar answered Nov 07 '22 22:11

dwickern