2017-06-05 146 views
0

我正在Lynda.com上運行一個教程,我試圖運行一個gulpfile,語法很好,但我無法理解終端的錯誤。嘗試在終端中運行時出現吞嚥錯誤(無語法錯誤)

任何人都可以爲我提供這方面的幫助嗎?

非常感謝!

gulpfile.js

var themename = 'pistol4'; 

var gulp = require('gulp'), 


autoprefixer = require('autoprefixer'), 
browserSync = require('browser-sync').create(), 
image = require(gulp - image), 
jshint = require('gulp-jshint'), 
postcss = require('gulp-postcss'), 
sass = require('gulp-sass'), 
sourcemaps = require('gulp-sourcemaps'), 

//Only work with new or updated files 
newer = require('gulp-newer'), 

//Name of working theme folder 
root = '../' + themename + '/', 
scss = root + 'sass/', 
js = root + 'js/', 
img = root + 'images/', 
languages = root + 'languages'; 

// CSS via Sass and Autoprefixer 
gulp.task('css', function() { 
return gulp.src(scss + '(style.css,rtl.scss)') 
.pipe(sourcemaps.init()) 
.pipe(sass({ 
    outputStyle: 'expanded', 
    indentType: 'tab', 
    indentWidth: '1' 
}).on('error', sass.logError)) 
.pipe(postcss([ 
    autoprefixer('last 2 versions', '> 1%') 
    ])) 
.pipe(sourcemaps.write(scss + 'maps')) 
.pipe(gulp.dest(root)); 
}); 

//Optimize images trough gulp-image 
gulp.task('images', function() { 
    return gulp.src(img + 'RAW/**/*.(jpg,JPG,png)') 
    .pipe(newer(img)) 
    .pipe(image()) 
    .pipe(gulp.dest(img)); 
}); 

//Javascript 

gulp.task('javascript', function() { 
    return gulp.src([js + '*.js']) 
    .pipe(jshint()) 
    .pipe(jshint.reporter('default')) 
    .pipe(gulp.dest(js)); 
}); 

//Watch everything 
gulp.task('watch', function() { 
    browserSync.init({ 
     open: 'external', 
     proxy: 'pistol.dev', 
     port: '8080' 
    }); 
    gulp.watch([root + '**/*.css', root + '**/*.scss'], ['css']); 
    gulp.watch(js + '**/*.js', ['javascript']); 
    gulp.watch(img + 'RAW/**/*.{jpg,JPG,png}', ['images']); 
    gulp.watch(root + '**/*').on('change', browserSync.reload); 
}); 

//Default task (runs at initiation: gulp --verbose) 
gulp.task('default', ['watch']); 

錯誤日誌從終端:

assert.js:81 
throw new assert.AssertionError({ 
^ 
AssertionError: missing path 
at Module.require (module.js:495:3) 
at require (internal/module.js:20:19) 
at Object.<anonymous> (C:\xampp\htdocs\pistol01.06.17\wp- 
content\themes\gulp-dev\gulpfile.js:7:10) 
at Module._compile (module.js:570:32) 
at Object.Module._extensions..js (module.js:579:10) 
at Module.load (module.js:487:32) 
at tryModuleLoad (module.js:446:12) 
at Function.Module._load (module.js:438:3) 
at Module.require (module.js:497:17) 
at require (internal/module.js:20:19) 
+1

image = require(gulp - image),這條線對我來說似乎很腥。 在這裏你定義一個var,哪個值是需要的模塊,哪個路徑是由圖像var本身定義的? 這可能會導致您的問題。 – Juan

+0

非常感謝Juan,確實是這個問題,我反正這個問題並且工作正常,但是在我遇到這個問題之後「[BS]無法打開瀏覽器(如果你在無頭環境中使用BrowserSync,你可能希望將打開選項設置爲false) 「我可以再次獲得您的幫助嗎?非常感謝!! –

+0

太棒了!你能解決這個問題嗎?如果沒有,你是否在公共公共公共回購中有這種情況?如果我們能克隆它,我們可以幫助你更好。 – Juan

回答

0

這條線:image = require(gulp - image),不會工作就像@Juan說。您的意思是:image = require('gulp-image'),

下一個錯誤:

"[BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false) "

因爲我從來沒有與瀏覽器同步工作,我只是猜測,寫的東西,我從Google上搜尋它找到。

我有兩個建議:

  1. 走進了「手錶」的任務和變化:browserSync.init({open: 'external', 到:在短browserSync.init({open: 'false',只是做了錯誤說的做。
  2. 您需要讓瀏覽器同步您打開瀏覽器的確切文件。 f.e .: '--browser "chrome.exe"'

請讓我們知道你是如何修復它或如果有任何幫助。

相關問題