带有分号插入的 Javascript 缩小 [英] Javascript minification with semicolon insertion

查看:61
本文介绍了带有分号插入的 Javascript 缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何 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"...

推荐答案

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

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"!

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

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.

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

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.

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

(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).

这篇关于带有分号插入的 Javascript 缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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