在Git bash中出现以下错误"语法错误:意外的标识符"使用Gulp在javascript中声明对象时

时间:2016-01-31 06:04:21

标签: javascript gulp

在Git bash&#34中出现以下错误:语法错误:意外的标识符"使用Gulp在javascript中声明对象时。它显示了代码的这一行中的错误:mainJS:' ./ src / main.js' SyntaxError:意外的标识符。我无法理解这个错误的原因。

"use strict";

var gulp = require('gulp');
var connect = require('gulp-connect');  // Runs a local dev server
var open = require('gulp-open');    // Open a URL in a web browser
var browserify = require('browserify'); // Bundles JS
var reactify = require('reactify'); // Transforms React JSX to JS
var source = require('vinyl-source-stream'); //Use conventional text streams     with Gulp


var config = {
port: 9005,
devBaseUrl: 'http://localhost',
paths: {
    html:  './src/*.html',
    js: './src/**/*.js',
    dist: './dist'
    mainJs: './src/main.js'
}

}

gulp.task('connect', function(){    
connect.server({
    root: '[dist]',
    port: config.port,
    base: config.devBaseUrl,
    livereload: true
});
});

gulp.task('open',['connect'], function(){   
gulp.src('dist/index.html')
    .pipe(open({ url:config.devBaseUrl + ':' + config.port + '/'}));
});

gulp.task('html',function(){        
gulp.src(config.paths.html)
    .pipe(gulp.src(config.paths.dist))  
    .pipe(connect.reload());
});

gulp.task('js', function(){
browserify(config.paths.mainJs)
    .transform(reactify)
    .bundle()
    .on('error', console.error.bind(console))
    .pipe(source('bundle.js'))
    .pipe(gulp.dest(config.paths.dist + '/scripts'))
    .pipe(connect.reload());
});


gulp.task('watch', function(){
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.js, ['js']);
});

gulp.task('default', ['html','js','open', 'watch']);    

1 个答案:

答案 0 :(得分:0)

您缺少逗号来分隔paths属性:

paths: {
  html:  './src/*.html',
  js: './src/**/*.js',
  dist: './dist'//Add a comma here
  mainJs: './src/main.js'
}