gulp ngmin + uglify无法正常工作 [英] Gulp ngmin + uglify not working properly
本文介绍了gulp ngmin + uglify无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
gulp.task('scripts',function(){
返回gulp.src(['app / js / app.js','app / config / config.js','app / js / controllers.js','app / js / directives.js','app / js /filters.js','app / js / footer.js',
'app / js / guideTour.js','app / js / mobileBanner.js','app / js / services.js', 'app / js / youtube.js','app / js / dataSync.js','app / js / addthis.js'])
//.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(ngmin())
.pipe(gulp。 dest('app / dist / js'))
.pipe(rename({suffix:'.min'}))
.pipe(uglify())
.pipe(gulp。 dest('app / dist / js'))
.pipe(livereload(server))
.pipe(notify({message:'Scripts task complete'}));
}) ;
问题在于,也是ngmin()输出的连接文件工作正常,但在uglifying代码之后,某些内容会中断,并且我得到以下错误。
没有具体的指示器可以开始调试。
堆栈trace:
错误:[$ injector:unpr] http://errors.angularjs.org/1.2.9/$injector / unpr?p0 = eProvider%20%3C-%20e
在http:// localhost:8000 / angular / angular.min.js:6:449
处出现错误(本机)
在http:// localhost:8000 / angular / angular.min.js:32:125
在Object.c [as get](http:// localhost:8000 / angular / angular.min.js:30 :200)
at http:// localhost:8000 / angular / angular.min.js:32:193
at c(http:// localhost:8000 / angular / angular.min.js: $ http:// localhost:8000 / angular / angular.min.js:30:417)
在Object.d [as invoke] 8000 / angular / angular-route.min.js:10:302
在Object.q [as forEach](http:// localhost:8000 / angular / angular.min.js:7:380)
在http:// localhost:8000 / angular / angular-route.min.js:10:248
解决方案
解决方案使用 mangle 选项将uglify任务设置为false 。
ie: .uglify({mangle:false})
整个代码:
gulp.task('scripts',function(){
return gulp.src('app / js / ** / * .js')
.pipe(jshint('。jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js')) )
.pipe(ngmin())
.pipe(gulp.dest('app / dist / js'))
.pipe(rename({suffix:'.min'}) )
.pipe(uglify({mangle:false}))
.pipe(gulp.dest('app / dist / js'))
.pipe(livereload(server))
.pipe(notify({message:'Scripts task complete'}));
});
I have the following gulp task:
gulp.task('scripts', function() {
return gulp.src(['app/js/app.js', 'app/config/config.js', 'app/js/controllers.js', 'app/js/directives.js' , 'app/js/filters.js', 'app/js/footer.js',
'app/js/guideTour.js', 'app/js/mobileBanner.js', 'app/js/services.js', 'app/js/youtube.js', 'app/js/dataSync.js', 'app/js/addthis.js'])
//.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(ngmin())
.pipe(gulp.dest('app/dist/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('app/dist/js'))
.pipe(livereload(server))
.pipe(notify({ message: 'Scripts task complete' }));
});
The problem is that the concatenated file which is also the output of ngmin(), is working fine, but after uglifying the code, something breaks, and I get the following error.
With no specific indicator where to start debugging.
Stack trace:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.9/$injector/unpr?p0=eProvider%20%3C-%20e
at Error (native)
at http://localhost:8000/angular/angular.min.js:6:449
at http://localhost:8000/angular/angular.min.js:32:125
at Object.c [as get] (http://localhost:8000/angular/angular.min.js:30:200)
at http://localhost:8000/angular/angular.min.js:32:193
at c (http://localhost:8000/angular/angular.min.js:30:200)
at Object.d [as invoke] (http://localhost:8000/angular/angular.min.js:30:417)
at http://localhost:8000/angular/angular-route.min.js:10:302
at Object.q [as forEach] (http://localhost:8000/angular/angular.min.js:7:380)
at http://localhost:8000/angular/angular-route.min.js:10:248
解决方案
Solution was running uglify task with mangle option set to false.
ie: .uglify({mangle: false})
whole code:
gulp.task('scripts', function() {
return gulp.src('app/js/**/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(ngmin())
.pipe(gulp.dest('app/dist/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('app/dist/js'))
.pipe(livereload(server))
.pipe(notify({ message: 'Scripts task complete' }));
});
这篇关于gulp ngmin + uglify无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文