Javascript 缩小并插入分号

发布于 2024-10-04 08:13:46 字数 99 浏览 1 评论 0原文

是否有任何 Javascript 压缩器/压缩器可以根据需要插入分号(或者,可以处理不使用分号的源代码)?我已经开始使用一个非常棒的库,但开发人员认为分号是“不必要的混乱”......

Is there any Javascript minifier/compressor which will insert semicolons as necessary (or, one which works with source code which doesn't use semicolons)? I've started using a library which is really great, but the developer considers the semicolons as "unnecessary clutter"...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎歌 2024-10-11 08:13:47

几年前,当我遇到类似的情况时,我似乎记得解决方案本质上是“越多越好”!

首先,我通过 Dojo Shrinksafe 在非常适度的压缩设置上运行脚本。因为它使用 Rhino,所以它实际上会解释 JS,然后用语法正确的分号写出等效版本。

从那里,我将输出输入 Dean Edward's /packer/,(至少在当时) )是产生一致功能输出的最高压缩库。该库要求输入带有分号,但由于 ShrinkSafe 的输出,这不是问题。

(请注意,这是凭记忆写的,我最近没有测试过,但是这个原则没有理由不再成立。如果 ShrinkSafe 不为你插入分号,也许还有其他一些 JS 预处理工具可以自动执行此操作?当然,分号插入并不是 100% 确定性的事实)。

When I was in a similar situation a couple of years ago, I seem to recall that the solution was essentially "the more the merrier"!

Firstly I ran the script through Dojo Shrinksafe on very modest compression settings. Because it uses Rhino, it would actually interpret the JS and then write out an equivalent version with syntactically correct semicolons.

From there, I fed the output into Dean Edward's /packer/, which (at the time, at least) was the highest-compression library that produced consistently functional output. This library requires the input to have semicolons, but that wasn't a problem thanks to the output from ShrinkSafe.

(Note that this is from memory and I haven't tested it recently, but there's no reason why the principle shouldn't hold any more. If ShrinkSafe doesn't insert semicolons for you, perhaps there's some other JS-preprocessing tool that will automatically do this? Modulo, of course, the fact that semicolon insertion is not 100% deterministic).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文