Microsoft Ajax Minifier不会缩短函数名

本文关键字:函数 Ajax Minifier Microsoft | 更新日期: 2023-09-27 18:08:31

我声明下面的javascript

window.myApp = {};
myApp.myVeryLongFunctionName = function()
{
    ...
};

然后我用以下代码(c#)缩小javascript

var minifiedCode = minifier.MinifyJavaScript(code, new CodeSettings
{
    RemoveUnneededCode = true,
    PreserveImportantComments = false,
    LocalRenaming = LocalRenaming.CrunchAll,
    EvalTreatment = EvalTreatment.MakeAllSafe,
    OutputMode = OutputMode.SingleLine,
    PreserveFunctionNames = false                        
});

但是"myApp"answers"veryLongFunctionName"不会被缩短,它被简化为这个。

window.myApp={};myApp.myVeryLongFunctionName=function(){};

我希望代码被简化成这样。

window.a={};a.b=function(){};

我需要哪些代码设置参数来实现这一点?

Microsoft Ajax Minifier不会缩短函数名

MinifyJavaScript()以字符串形式返回缩小后的代码。试试这个:

var s = minifier.MinifyJavaScript(code, new CodeSettings
{
  RemoveUnneededCode = true,
  PreserveImportantComments = false,
  LocalRenaming = LocalRenaming.CrunchAll,
  EvalTreatment = EvalTreatment.MakeAllSafe,
  OutputMode = OutputMode.SingleLine,
  PreserveFunctionNames = false                        
});
Console.WriteLine(s);