Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit line length with requirejs + uglify

We're using requirejs.optimize(config) with uglify2 in our build scripts to minify our production JavaScript code. We want to limit the minified line length to about 80 chars, so that it will be easier to debug JavaScript errors even from the production code. (Most browsers only report the line number, not the column, in the onerror handler, so source maps do not help.)

Uglify2 contains the max-line-len option in the beautifier options. I've tried many different combinations of the following options, but haven't been able to get the code minified, but with limited line length:

config = {
  optimize: 'uglify2',
  uglify2: {
    output: {
      beautify: true
    },
    beautify: {
      beautify: false,
      max_line_len: 80
    }
  },
  // ...
}

How can I pass the option to limit the line length to uglify2?

like image 459
Sampo Avatar asked Nov 19 '13 22:11

Sampo


1 Answers

Finally managed to figure out the necessary combination:

config = {
  optimize: 'uglify2',
  uglify2: {
    output: {
      max_line_len: 80
    }
  },
  // ...
}
like image 195
Sampo Avatar answered Sep 22 '22 13:09

Sampo