Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
738 views
in Technique[技术] by (71.8m points)

gulp 压缩后angular报错问题

有以下bower来的文件,如下

clipboard.png

经过gulp合并压缩后
clipboard.png

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

如果你想采用缩写,那你在gulp的流程里加上gulp-ng-annotate这个插件。
var ngAnnotate = require('gulp-ng-annotate');

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

以下是原理:
依赖是按字符串找的,在写的时候自己主动写上依赖,不要缩写。
比如正式的写法是
angular.module('adminApp').controller('TestCtrl', ['$scope',function($scope) {}])
然后一般你可以缩写为
angular.module('adminApp').controller('TestCtrl', [function($scope) {}])
但是缩写的方式在压缩合并之后就会报错。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...