2017-04-24 97 views
1

我有一個AngularJS應用程序,爲此我使用了bower,npm和gulp。此代碼是工作前幾天,不知道爲什麼,但我得到了下面的時候我做了一口命令:Gulp:SyntaxError:意外的JSON輸入結束

gulp minifycss; 

錯誤:

SyntaxError: Unexpected end of JSON input 
at Object.parse (native) 
at module.exports (..\node_modules\main-bower-files\lib\index.js:48:43) 
at Gulp.<anonymous> (..\gulpfile.js:72:33) 
at module.exports (..\node_modules\orchestrator\lib\runTask.js:34:7) 
at Gulp.Orchestrator._runTask (..\node_modules\orchestrator\index.js:273:3) 
at Gulp.Orchestrator._runStep (..\node_modules\orchestrator\index.js:214:10) 
at Gulp.Orchestrator.start (..\node_modules\orchestrator\index.js:134:8) 
at C:\Users\bgi5\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20 
at _combinedTickCallback (internal/process/next_tick.js:73:7) 
at process._tickCallback (internal/process/next_tick.js:104:9) 

咕嘟咕嘟代碼:

var cleanCss = require('gulp-clean-css'), 
filter = require('gulp-filter'), 
concat = require('gulp-concat'), 
merge = require('merge-stream'), 
bowerFiles = require('main-bower-files'); 
var config = { 
paths: { 
    src: './src', 
    build: './build', 
    bower: './bower_components' 
} 
}; 
gulp.task('minifyCss', function() { 
var v= gulp.src(bowerFiles()) 
    .pipe(filter(['**/*.css'])) 
    .pipe(concat('v.css')) 
    .pipe(cleanCss({debug: true})) 
    .pipe(gulp.dest(config.paths.build + '/styles')); 

var a= gulp.src(config.paths.src + '/**/*.css') 
    .pipe(concat('a.css')) 
    .pipe(cleanCss({debug: true})) 
    .pipe(gulp.dest(config.paths.build + '/styles')); 

return merge(v, a); 
}); 

回答

2

這是由代碼中的變量bowerFiles造成的。

bowerFiles = require('main-bower-files');

出於某種原因,沒有發現從涼亭包你已經安裝了所需的CSS文件。由於錯誤提到了JSON的一些問題,我想你的bower配置文件.bowerrc有問題。仔細檢查它指向的涼亭目錄是否正確。點擊這裏link瞭解更多關於.bowerrc文件的信息。