2016-12-25 9 views
0

私はビルドシステムでは初心者ですので、githubのサンプルgulpfileを自分のgulpfileを作成するためのガイドとして使用しました。成功しましたが、最近は、sassファイルまたはjsファイルに単一のエラーがあると、gulpはエラーメッセージを表示し、サーバー(browsersyncサーバー)が停止することに気付きました。sassファイルまたはjsファイルにエラーがある場合はいつでもGulpサーバーが停止します

Gulpfile.js

'use strict'; 

const gulp = require('gulp'); 
const sass = require('gulp-sass'); 
const uglify = require('gulp-uglify'); 
const concat = require('gulp-concat'); 
const autoprefixer = require('gulp-autoprefixer'); 
const browserSync = require('browser-sync'); 

gulp.task('styles',() => { 
    return gulp.src('assets/styles/sass/style.sass') 
    .pipe(sass({outputStyle: 'compressed'})) 
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4')) 
    .pipe(gulp.dest('assets/styles/')) 
    .pipe(browserSync.stream()); 
}); 

gulp.task('scripts',() => { 
    return gulp.src('assets/js/src/*.js') 
     .pipe(concat('main.js')) 
     .pipe(gulp.dest('assets/js/build')) 
     .pipe(uglify()) 
     .pipe(gulp.dest('assets/js/')) 
     .pipe(browserSync.stream()); 
}); 

gulp.task('serve', ['styles', 'scripts'],() => { 
    browserSync.init({ 
     server: { 
      baseDir: './' 
     }, 
     notify: false 
    }); 

    gulp.watch('assets/styles/sass/style.sass', ['styles']); 
    gulp.watch('assets/js/src/*.js', ['scripts']); 
    gulp.watch('index.html').on('change', browserSync.reload); 
}); 

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

私はstylesタスクに追加するプロパティやメソッドはありますか?

答えて

1

ほとんどの人はこれにgulp-plumberを使用しているようです。私はあなたのサスペルのエラー報告を表示したい場合は、エラー報告ala

.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) 

を含めるようにあなたのサスパイプを修正します。最後に、「styles」と「scripts」のbrowserSync.streamパイプをこれに変更します。

.pipe(browserSync.reload({ stream:true })); 
+0

ありがとう、バディ:) – jst16

関連する問題