7

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
dwickern
  • 3,519
  • 1
  • 14
  • 21
  • The use of `in Assets` and not is probably `pipelineStages` specific. Do you need to run `uglify` in dev? – Dale Wijnand May 13 '15 at 23:29
  • 1
    It's only used to concatenate all `*.js` into one file. I couldn't use `sbt-concat` for reasons I can't recall. – dwickern May 14 '15 at 01:17

1 Answers1

1

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

dwickern
  • 3,519
  • 1
  • 14
  • 21