当我发布我的 .NET 应用程序时,我的 JS 文件之一没有正确缩小。我在文件中有几百行代码,但在该过程完成后最终得到了一个近乎空的函数。我已经完成了它并确定它取决于$.noop我使用的一个,没有它这个过程可以正常工作。为了证明这一点,我将其分解为一个简单的示例,显示它如何影响文件。
var MyApp = {};
MyApp.EmailPopup = (function () {
function Test() {
// do lots of jquery stuff
alert('hi');
}
var thisObject = {
Show: $.noop
};
thisObject.Show = function () {
Test();
};
return thisObject;
})();
缩小后,调用Test被删除,如图所示:
var MyApp={};MyApp.EmailPopup=function(){return{Show:$.noop}}();
但是,如果我删除该$.noop函数并添加一个空函数,如下所示:
var MyApp = {};
MyApp.EmailPopup = (function () {
function Test() {
// do lots of jquery stuff
alert('hi');
}
var thisObject = {
Show: function () { } // this has changed
};
thisObject.Show = function () {
Test();
};
return thisObject;
})();
然后我得到所需的缩小版本:
var MyApp={};MyApp.EmailPopup=function(){return{Show:function(){alert("hi")}}}();
在真正的应用程序中,由于它不包括等效Test功能,我丢失了数百行代码。有人可以解释为什么 using$.noop会阻止它工作,但初始化为空函数或 null 有效吗?它是一个 .NET 4.8 Web 应用程序,它使用 jQuery 3.3.1,我使用 Visual Studio 2019 构建它。