2017-04-30 3 views
0

Browser Syncを使用してファイルの変更を監視するPHPサーバをローカルに作成したいとします。ブラウザで新しいタブを開き、index.phpファイルの内容を表示したいと思います。マイgulpfile.js:PHPサーバとブラウザ同期のためのgulpfile.jsの設定

var gulp = require('gulp'); 
var browserSync = require('browser-sync').create(); //reloading while saving file 
var php = require('gulp-connect-php'); //for PHP server 

// ------------------------------------------------- // 
// --------- Server and watching for changes --------// 
// ------------------------------------------------- // 


gulp.task('php', function() { 
    php.server({ base: 'src', port: 8080, keepalive: true, hostname: 'localhost'}); 
}); 

gulp.task('browser-sync',['php'], function() { 
    browserSync.init({ 
     proxy: '127.0.0.1', 
     port: 8080 
    }); 
}); 

gulp.task('htmlServer', function() { 
    gulp.src(['src/*.+(html|ico|php)']) 
    .pipe(browserSync.reload({ 
     stream: true 
    }));; 
}); 

gulp.task('stylesServer', function() { 
    gulp.src(['src/styles/*.css']) 
    .pipe(browserSync.reload({ 
     stream: true 
    })); 
}); 

gulp.task('jsServer', function() { 
    gulp.src(['src/scripts/*.js']) 
    .pipe(browserSync.reload({ 
     stream: true 
    })); 
}); 

// --------- wrapped together --------- // 

gulp.task('server', ['browser-sync','php','htmlServer','stylesServer','jsServer'], function() { 
    gulp.watch('src/styles/*.css',['stylesServer']); 
    gulp.watch('src/*.+(html|php)',['htmlServer']); 
    gulp.watch('src/scripts/*.js',['jsServer']); 
}); 

しかし、私はそれがブラウザで新しいタブを飛び出して、画面上のようにロードし続けてゴクゴクサーバータスクを起動するとき:

enter image description here

誰かが私を助けることができますか?私は多くのチュートリアルを見ていましたが、何も働かず、私はもっと混乱したくありません。あなたの助けをあらかじめありがとうございます。

答えて

0
var gulp = require('gulp'); 
var browserSync = require('browser-sync').create(); //reloading while saving file 
var php = require('gulp-connect-php'); //for PHP server 

チェックあなたはgulp.phpを書いて、あなたは、ファイルの拡張子を追加する必要があります任意のファイル名を呼ぶところ、あなたはあなたのプロジェクトでこのファイルを呼び出すために必要としていたあなたは一口を書きますが、このセクション

関連する問題