Gulp.task意外令牌

时间:2017-03-29 13:00:55

标签: node.js gulp

我创建了一个package.json并运行npm install后跟gulp,但它在第一个gulp.task()

上引发了错误
  

SyntaxError:意外的令牌。

{
  "name": "theme",
  "version": "1.0.0",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "browser-sync": "^2.12.5",
    "gulp": "^3.9.1",
    "gulp-compass": "^2.1.0",
    "gulp-concat": "^2.6.0",
    "gulp-html": "^0.4.4",
    "gulp-htmlmin": "^2.0.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^1.5.3"
  }
}

gulp.js

   var gulp = require('gulp'),
    path = require('path'),

    // CSS
    compass = require('gulp-compass'),
    minifyCSS = require('gulp-minify-css'),

    // JS BUILD
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),

    // HTML
    htmlmin = require('gulp-htmlmin'),

    // Browser sync
    browserSync = require('browser-sync'),

    // Import files
    pkg = require('./package.json'),


gulp.task('js', function () {
        gulp.src(['scripts/*.js'])
            .pipe(concat(pkg.name + '.js'))
            .pipe(gulp.dest('/'))
            .pipe(rename(pkg.name + '.min.js'))
            .pipe(uglify())
            .pipe(gulp.dest('/'));
});

gulp.task('compass', function(){
    gulp.src('_sass/**/*.scss')
        .pipe(compass({
            css: 'css/',
            sass: 'sass/',
            image: 'images/',
            logging: true,
            style: 'compressed'
        }))
        .on('error', function(error){
            console.log('Compass Error')
            console.log(error)
        })
        .pipe(minifyCSS({
            keepBreaks: false,
            keepSpecialComments:true
        }))
        .pipe(gulp.dest('css/'));
});


gulp.task('default', ['compass', 'js'], function (event) {
    gulp.watch('sass/**/*.scss', ['compass']);
    gulp.watch('scripts/**/*.js', ['js']);
});

编辑:Gulp在本地和全球安装

1 个答案:

答案 0 :(得分:0)

刚看到我的上一次导入有一个逗号,导致该错误

pkg = require('./package.json'),

需要

pkg = require('./package.json')