首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于js错误过多,Gulp.js无法编译angular.js项目?

由于js错误过多,Gulp.js无法编译angular.js项目?
EN

Stack Overflow用户
提问于 2014-05-06 20:59:19
回答 1查看 2K关注 0票数 2

我正试着从Grunt转到Gulp。这个项目在Grunt下运行得很好,所以我一定是在Gulp中做错了什么。

除了脚本之外,所有其他任务都可以工作。我现在已经厌倦了添加和注释部分。

我一直收到一个与意外令牌有关的错误。使用mg-min:

代码语言:javascript
复制
stream.js:94
  throw er; // Unhandled stream error in pipe.
        ^
Error: Line 2: Unexpected token :
at throwError (/Users/stevelombardi/Documents/dsg/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:1156:21)

将ng-min注释掉并使用Uglify (默认):

代码语言:javascript
复制
Error caught from uglify: Unexpected token: punc (:) in /Users/stevelombardi/Documents/dsg/dist/scripts/main.min.js. Returning unminifed code
[gulp] gulp-notify: [Gulp notification] Scripts task complete
[gulp] Finished 'scripts' after 2.97 s

我被难住了。这是我们的任务:

代码语言:javascript
复制
// Scripts
gulp.task('scripts', function() {
return gulp.src([
    "bower_components/jquery/jquery.js",
    "bower_components/angular/angular.js",
    "bower_components/bootstrap/dist/js/bootstrap.js",
    "bower_components/modernizr/modernizr.js",
    "bower_components/angular-resource/angular-resource.js",
    "bower_components/angular-cookies/angular-cookies.js",
    "bower_components/angular-sanitize/angular-sanitize.js",
    "bower_components/angular-route/angular-route.js",
    "bower_components/jquery.easy-pie-chart/dist/angular.easypiechart.js",
    "bower_components/angular-bootstrap/ui-bootstrap.min.js",
    "bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js",
    "bower_components/kapusta-jquery.sparkline/dist/jquery.sparkline.js",
    "bower_components/leaflet-dist/leaflet.js",
    "bower_components/angular-leaflet/dist/angular-leaflet-directive.js",
    "bower_components/ngprogress/build/ngProgress.js",
    "bower_components/angular-bootstrap-toggle-switch/angular-toggle-switch.js",
    "bower_components/flot/jquery.flot.js",
    "bower_components/flot/jquery.flot.resize.js",
    "bower_components/flot.tooltip/js/jquery.flot.tooltip.js",
    "bower_components/angular-flot/angular-flot.js",
    'src/scripts/**/*.js',
])
    .pipe(jshint('.jshintrc'))
    .pipe(jshint.reporter('default'))

// .pipe(ngmin({
//     dynamic: false
// }))
// .pipe(gulp.dest('dist/scripts'))

.pipe(concat('main.js'))
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({
    suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
    .pipe(notify({
        message: 'Scripts task complete'
    }));
});
EN

回答 1

Stack Overflow用户

发布于 2014-05-07 10:40:37

我认为可以肯定地说,这两个插件的输出可以被认为是在传递给ngmin或uglify的内容的第二行出现了语法错误。

这两个插件只是反应有点不同而已。一个是有用的告诉你行号,另一个是有用的告诉你文件名。

因为您已经重命名了该文件,所以看起来他们谈论的是一个已经缩小的文件,而实际上只是您过早地重命名了它在内存中的表示。

对于初学者,我建议您在缩小文件之前不要重命名它,因为您的错误很容易混淆。此时,您可能会看到错误出现在保存到dist/scripts/main.js的文件中(在该文件的第二行,您显然有一个错误的冒号)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23495436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档