我正试着从Grunt转到Gulp。这个项目在Grunt下运行得很好,所以我一定是在Gulp中做错了什么。
除了脚本之外,所有其他任务都可以工作。我现在已经厌倦了添加和注释部分。
我一直收到一个与意外令牌有关的错误。使用mg-min:
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 (默认):
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我被难住了。这是我们的任务:
// 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'
}));
});发布于 2014-05-07 10:40:37
我认为可以肯定地说,这两个插件的输出可以被认为是在传递给ngmin或uglify的内容的第二行出现了语法错误。
这两个插件只是反应有点不同而已。一个是有用的告诉你行号,另一个是有用的告诉你文件名。
因为您已经重命名了该文件,所以看起来他们谈论的是一个已经缩小的文件,而实际上只是您过早地重命名了它在内存中的表示。
对于初学者,我建议您在缩小文件之前不要重命名它,因为您的错误很容易混淆。此时,您可能会看到错误出现在保存到dist/scripts/main.js的文件中(在该文件的第二行,您显然有一个错误的冒号)。
https://stackoverflow.com/questions/23495436
复制相似问题