0

I am looking for a way for making r.js (RequireJS' optimization script) ugylyfying our JS-modules BUT letting the line breaks remain. Im using uglify2 as my optimize value.

  optimize:                   'uglify2',

in my build script. I can do "optimize : none", but i want my files to me minified, i just want to preserve line numbers. is there an option to do that with uglify? is there an equivalent to "closure.keepLines" for uglify2 ??

Requirejs optimization doc http://requirejs.org/docs/optimization.html#options https://github.com/jrburke/r.js/blob/master/build/example.build.js

Charles
  • 48,924
  • 13
  • 96
  • 136
ghostCoder
  • 7,009
  • 8
  • 43
  • 63

1 Answers1

3

You can pass this to your r.js configuration:

optimize: 'uglify2',
uglify2: {
  output: {
    beautify: true,
  },
  beautify: {
    semicolons: false
  }
}

It will not really keep the original line breaks, but rather beautify the the uglified code. The semicolon option will seperate statements with line breaks rather that with semicolons. There are other options to play with, you can find the all at https://github.com/mishoo/UglifyJS2

I commit js files compiled by requirejs to my git repo and I found these settings work pretty well (diffs of compiled files are pretty clean).

lukaszfiszer
  • 2,271
  • 17
  • 13