2014-07-22 3 views
1

내 gulpfile은 다음과 같다 :내가 Node.js를하고 쭉 마시는를 사용하는 경우 livereload가 동작하지 않습니다

var gulp = require('gulp'), 
    connect = require('gulp-connect'), 
    sass = require('gulp-ruby-sass'), 
    autoprefixer = require('gulp-autoprefixer'), 
    minifycss = require('gulp-minify-css'), 
    jshint = require('gulp-jshint'), 
    uglify = require('gulp-uglify'), 
    imagemin = require('gulp-imagemin'), 
    rename = require('gulp-rename'), 
    clean = require('gulp-clean'), 
    concat = require('gulp-concat'), 
    notify = require('gulp-notify'), 
    cache = require('gulp-cache'), 
    livereload = require('gulp-livereload'); 

gulp.task('styles', function() { 
    return gulp.src('main.scss') 

    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.$ 
    .pipe(gulp.dest('css')) 
    .pipe(rename({suffix: '.min'})) 
    .pipe(minifycss()) 
    .pipe(gulp.dest('css')); 
}); 

    gulp.task('default', function() { 
    gulp.start('styles'); 
    gulp.start('server'); 
    gulp.start('watch'); 
}); 


gulp.task('server', function() { 
    connect.server({ 
     livereload:true 
    }); 
}); 


gulp.task('indexChange',function(){ 
    console.log('index has changed'); 
    connect.reload(); 
}); 

gulp.task('watch', function() { 

    gulp.watch('index.html', ['indexChange']); 


}); 

내 index.html 파일을 변경할 때 'indexChange'작업이 실행하고 콘솔 출력 ' 인덱스가 변경되었습니다 '하지만 connect.reload()는 아무 것도하지 않습니다.

나는 두 서버가 모두 실행 중임을 알기 위해 liverload 포트와 connect 서버 포트를 확인했습니다. 그러나 livereload가 작동하기 위해 내가 누락 된 코드를 파악할 수는 없습니다.

내가 뭘 잘못하고 있니?

답변

1

파이프를 connect.reload()에 반환해야합니다. 작동하려면 시험해보십시오.

// add gulp-watch 
var watch = require('gulp-watch'); 

gulp.task('indexChange',function(){ 
    console.log('index has changed'); 
}); 

gulp.task('watch', function() { 
    watch({glob: './index.html'}, ['indexChange']).pipe(connect.reload()); 
}); 
+0

고마워요! 그게 효과가 있었어! – user1577173