使用requirejs + uglify限制行长度 [英] Limit line length with requirejs + uglify

查看:114
本文介绍了使用requirejs + uglify限制行长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在构建脚本中使用 requirejs.optimize(config)和uglify2来缩小我们的生产JavaScript代码。我们希望将缩小的行长度限制为大约80个字符,这样即使从生产代码中调试JavaScript错误也会更容易。 (大多数浏览器只报告onerror处理程序中的行号,而不是列,因此源映射没有帮助。)

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包含 max-line-len 选项。我已经尝试了以下选项的许多不同组合,但是无法使代码缩小,但行长度有限:

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
    }
  },
  // ...
}

如何通过选项将行长度限制为uglify2?

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

推荐答案

最后设法找出必要的组合:

Finally managed to figure out the necessary combination:

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

这篇关于使用requirejs + uglify限制行长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆