[英]How does Grunt minify or uglify IIFE?
在标准的咕unt grunt serve
,我在指令之一附近使用IIFE,如下所示:
(function() {
"use strict";
angular.module('napiRest')
.directive('componentStaffReport', ['$modal', 'ComponentStaffFactory', function ($modal, ComponentStaffFactory) {
return {
restrict: 'E',
transclude: true,
scope: {
componentId: '=componentId',
linkableContent: '=linkableContent'
},
templateUrl: 'app/pages/report/component-staff/component-staff-popup.html',
link: function (scope, element, attr) {
ComponentStaffFactory.componentId = scope.componentId;
var modalInstance = null;
scope.open = function () {
modalInstance = $modal.open({
templateUrl: 'ComponentStaffModal.html',
controller: 'ComponentStaffingCtrl',
size: 'lg',
backdrop: true,
windowClass: 'x-x-large-modal'
});
ComponentStaffFactory.modalInstance = modalInstance;
};
} //link
}; //return
}])
})();
当我随后使用grunt serve:dist
进行部署时,此方法不起作用。 我收到错误: Uncaught TypeError: object is not a function
但是,当我卸下周围的IIFE时,它将正常工作。 这是否是由于dist发出咕声或缩小声而导致的?
似乎此问题是由于另一个文件中缺少分号引起的。 另一个文件是一个角度控制器,结尾没有分号。 当grunt将代码丑化时,它欺骗了该文件和上面的文件,共同创建了自己的匿名函数,编译器当然不喜欢它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.