Javascript Gulp - 错误 SyntaxError: Unexpected token

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32151417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:40:45  来源:igfitidea点击:

Gulp - error SyntaxError: Unexpected token

javascriptgulp

提问by Mike

I am trying to understand Gulp. I am on a Windows platform.

我正在尝试了解 Gulp。我在 Windows 平台上。

I have a simple gulpfile.js- but I keep getting

我有一个简单的gulpfile.js- 但我不断得到

SyntaxError. Unexpected token/identifier

语法错误。意外的令牌/标识符

I think it is saying identifier gulpis wrong but not sure. If it is, I'm not sure how I should set-up the gulpfileor what identifier to use

我认为这是说标识符gulp错误但不确定。如果是,我不确定应该如何设置gulpfile或使用什么标识符

Sorry I can't post picture of log -- Here is gulpfile code

抱歉,我无法发布日志图片——这是 gulpfile 代码

var gulp        = require('gulp');
var uglify      = require('gulp-uglify'); 

gulp.task('scripts', function () {
    gulp.src('assets/js/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/assets/js'));
});

gulp.task('styles', function () {

    gulp.src('assets/css/*.css')
    .pipe(uglify())
    .pipe(gulp.dest('build/assets/css'));
});

gulp.task('default', ['scripts', 'styles']
    gulp.src('assets/js/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/assets/js'));

回答by joyBlanks

gulp.task('default', ['scripts', 'styles'], function(){
    gulp.src('assets/js/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/assets/js'));
});

add function(){ /*logic*/ });you missed this in default

添加function(){ /*logic*/ });你在默认情况下错过了这个

回答by Mike

Thanks - Yes, I missed function() - now gulp gives a ReferenceError: uglyfly is not defined. Here is code again

谢谢 - 是的,我错过了 function() - 现在 gulp 给出了一个 ReferenceError: 丑蝇未定义。这里又是代码

var gulp        = require('gulp'),
    uglify      = require('gulp-uglify'); 
gulp.task('scripts', function() {
  gulp.src('assets/js/*.js')
    .pipe(uglyfly())
    .pipe(gulp.dest('build/assets/js'))
});
gulp.task('styles', function() {
  gulp.src('assets/css/*.css')
    .pipe(uglyfly())
    .pipe(gulp.dest('build/assets/css'))
});

gulp.task('default', ['scripts', 'styles'], function () {

});