简体   繁体   English

使用uglify grunt任务搞砸了selectivizr

[英]Using uglify grunt task messes up selectivizr

I have a Yeoman project that uses grunt-contrib-uglify on its Javascript files. 我有一个Yeoman项目,它在其Javascript文件上使用grunt-contrib-uglify When run on the Selectvizr library (pulled in using Bower) the resultant file looks like this: 在Selectvizr库上运行(使用Bower引入)时,生成的文件如下所示:

!function(win){return}(this);

I think that's because Selectivizr is setup to not do anything if the browser isn't IE, so perhaps in the Grunt execution context it's doing just that? 我认为这是因为如果浏览器不是IE,Selectivizr会设置为什么都不做,所以也许在Grunt执行环境中它正在做的那样?

So I want to know if it's possible to have Uglify run on Selectivizr and produce something usable? 所以我想知道是否可以在Selectivizr上运行Uglify并生成可用的东西?

Uglify processes the JavaScript for the sole purpose of optimization. Uglify处理JavaScript仅用于优化。 Its job is to make the file super small in any way possible. 它的工作是以任何可能的方式使文件超小。 To do this, it detects any non-variable conditions in the code, such as if (true) { return; } 为此,它会检测代码中的任何非变量条件,例如if (true) { return; } if (true) { return; } . if (true) { return; } Since true is always true, the functionality of this conditional is interpreted, and optimized for. 由于true始终为true,因此将对此条件的功能进行解释和优化。

So, it's not an Uglify bug, since it did its job correctly. 所以,它不是一个Uglify错误,因为它正确地完成了它的工作。 I'm not familiar with the trick Selectivizr is using, but if it works, it works. 我不熟悉Selectivizr正在使用的技巧,但如果它有效,它就可以了。

Unfortunately, the only solution I can think of is not letting Uglify run on the file, and instead copy it over to dist/ directly. 不幸的是,我能想到的唯一解决方案就是不让Uglify在文件上运行,而是直接将其复制到dist/

var result = navigator.userAgent.match(/MSIE (\d+)/);
if (result) {
  var ieVersion = result[1];
}
else {
  return;
}

Please use the above code to fix this issue. 请使用上面的代码来解决此问题。 I too got the same issue and it has been fixed after updating this line. 我也遇到了同样的问题,并且在更新此行后已修复。

The other solution is to comment/delete the line 32 in selectivizr.js : 另一种解决方案是在selectivizr.js中注释/删除第32行

if (/*@cc_on!@*/true) return;

This is the line breaking the uglify/concat task. 这是打破uglify / concat任务的行。 Run again and it will work. 再次运行它会工作。

More on Github 更多关于Github

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM