Limit line length with requirejs + uglify
Asked Answered
Z

1

6

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?

Zoochore answered 19/11, 2013 at 22:44 Comment(0)
Z
6

Finally managed to figure out the necessary combination:

config = {
  optimize: 'uglify2',
  uglify2: {
    output: {
      max_line_len: 80
    }
  },
  // ...
}
Zoochore answered 19/11, 2013 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.