我在Javascript Bundles&中添加了淘汰js文件在发布模式下,这些都是缩小的。调试模式下一切正常。但是,当优化工作正在进行时JsBundles由Visual Studio自动缩小,它会更改引发问题的参数名称。例如:
在Prettify之后缩小文件
function ProgramViewModel() {
var n = this;
n.Programs = ko.observableArray([]);
n.SelectProgramForDetails = ko.observable('');
n.SelectedProgramList = ko.observableArray([]);
n.RequestedPrograms = ko.observableArray([]);
n.SelectedPrograms = ko.observableArray([]);
n.SearchSelected = ko.observable(!1);
n.ProgramName = ko.observable('');
n.CurrentPage = ko.observable(0);
n.LastHeight = ko.observable(0);
n.ProgramCatalog = ko.observableArray([{
CatalogName: 'Global Catalog',
CatalogId: 1
},
{
CatalogName: 'Area Catalog',
CatalogId: 2
}
]);
n.ColumnClicked = function (n, t) {
paginationViewModel.ColumnClicked(t);
programViewModel.GetPrograms()
};
n.ShowData = function (n) {
$('html, body').animate({
scrollTop: paginationViewModel.offset()
}, 500);
paginationViewModel.ShowData(n);
programViewModel.GetPrograms()
};
}
之前的文件
function ProgramViewModel() {
var self = this;
self.Programs = ko.observableArray([]);
self.SelectProgramForDetails = ko.observable("");
self.SelectedProgramList = ko.observableArray([]);
self.RequestedPrograms = ko.observableArray([]);
self.SelectedPrograms = ko.observableArray([]);
self.SearchSelected = ko.observable(false);
self.ProgramName = ko.observable("");
self.CurrentPage = ko.observable(0);
self.LastHeight = ko.observable(0);
// Default Catalog for now
self.ProgramCatalog = ko.observableArray([
{ CatalogName: "Global Catalog", CatalogId: 1 },
{ CatalogName: "Area Catalog", CatalogId: 2 }
]);
self.ColumnClicked = function (data, e) {
paginationViewModel.ColumnClicked(e);
programViewModel.GetPrograms();
};
self.ShowData = function (mode) {
$('html, body').animate({
scrollTop: paginationViewModel.offset()
}, 500);
paginationViewModel.ShowData(mode);
programViewModel.GetPrograms();
};
}
问题是minifier不知道范围内的关键字,因此将同一范围内的变量名称更改为现有名称。当在该范围内有一个n
命名变量时,它会再次将其他函数变量重命名为n(可能会发出或者可能不会发出,不太确定)。
任何可以帮助更有效地缩小KnockoutJs文件的minify工具?
答案 0 :(得分:1)
Uglifyjs2具有可以关闭的mangler选项,只保留变量名称:https://github.com/mishoo/UglifyJS2#mangler-options