为什么gulp-sprite-generator抛出"语法错误:意外的令牌;"?

时间:2014-11-19 13:08:05

标签: javascript gulp gulp-watch

运行我的gulp任务我得到以下错误:SyntaxError: Unexpected token ; - 我想知道这与我的Gulp任务有什么关系?

var gulp = require('gulp');
var sprite = require('gulp-sprite-generator');

gulp.task('sprites', function() {
    var spriteOutput;

    spriteOutput = gulp.src("src/css/*.css")
        .pipe(sprite({
            baseUrl:         "src/image/",
            spriteSheetName: "sprite.png",
            spriteSheetPath: "dist/image/"
        });

    spriteOutput.css.pipe(gulp.dest("dist/css/"));
    spriteOutput.img.pipe(gulp.dest("dist/image/"));
});

gulp.task('default', ['sprites']);

我已经安装了代码中提到的两个模块。我在根目录中有我的gulp文件,并且还创建了src baseUrl目录。在我的css目录中,我有一个简单的.css文件,其中包含以下内容:

#image1 {
    background: url("../image/banana.png") no-repeat;
    width: 165px;
    height: 146px;
}

作为参考,这是gulp-sprite-generator

来自控制台的完整错误:

C:\FILE-PATH\gulp\gulp-sprite-generator>gulp

C:\FILE-PATH\gulp\gulp-sprite-generator\gulpf
ile.js:12
        });
          ^
SyntaxError: Unexpected token ;
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Liftoff.handleArguments (C:\NPM-PATH\Roaming\npm\node_modules\gu
lp\bin\gulp.js:116:3)
    at Liftoff.<anonymous> (C:\NPM-PATH\Roaming\npm\node_modules\gulp\n
ode_modules\liftoff\index.js:159:12)
    at module.exports (C:\NPM-PATH\Roaming\npm\node_modules\gulp\node_m
odules\liftoff\node_modules\flagged-respawn\index.js:17:3)
    at Liftoff.launch (C:\NPM-PATH\Roaming\npm\node_modules\gulp\node_m
odules\liftoff\index.js:152:5)

1 个答案:

答案 0 :(得分:0)

您似乎错过了以下代码中的结束)

spriteOutput = gulp.src("src/css/*.css")
    .pipe(sprite({
        baseUrl:         "src/image/",
        spriteSheetName: "sprite.png",
        spriteSheetPath: "dist/image/"
    }));

那应该解决这个错误。