search

Home  >  Q&A  >  body text

angular.js - gulp 压缩后angular报错问题

有以下bower来的文件,如下

经过gulp合并压缩后

如果不压缩正确运行。有没有朋友们使用上述依赖压缩后发生同样问题的?这种问题要怎么排查?

滿天的星座滿天的星座2744 days ago863

reply all(4)I'll reply

  • 黄舟

    黄舟2017-05-15 17:14:41

    If you want to use abbreviations, add the gulp-ng-annotate plug-in to the gulp process.
    var ngAnnotate = require('gulp-ng-annotate');

    gulp.task('useref-ftl', function () {
        return gulp.src(*******)
            .pipe(gulpif('*.js', ngAnnotate()))
    });

    The following is the principle:
    Dependencies are found by strings. When writing, take the initiative to write the dependencies without abbreviating them.
    For example, the formal writing method is
    angular.module('adminApp').controller('TestCtrl', ['$scope',function($scope) {}])
    Then generally you can abbreviate it to
    angular.module(' adminApp').controller('TestCtrl', [function($scope) {}])
    But the abbreviated method will report an error after compression and merging.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-15 17:14:41

    Has the reference path changed after compression

    reply
    0
  • 某草草

    某草草2017-05-15 17:14:41

    var myModule = angular.module('myApp', []);
        myModule.controller('myCtrl', ['$scope', 'Project', function($scope, Project) {
    
        }]);
    
      var myModule = angular.module('myApp', []);
        myModule.controller('myCtrl', , function($scope, Project) {
    
        });
        没加方括号压缩后可能有问题

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-15 17:14:41

    Dependencies are found based on strings. When writing, you take the initiative to write the dependencies, because variables and other things will change after compression, and Angular cannot find it by itself.

    reply
    0
  • Cancelreply