我想在本地创建一个PHP服务器,通过浏览器同步监视我的文件的更改。我想让它在我的浏览器中打开新的标签并显示index.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']);
});但当我启动gulp服务器任务时,它会在浏览器中弹出新的选项卡,并继续加载,就像在屏幕上一样:

有人能帮我吗?我看了很多教程,但都不起作用,我不想变得越来越困惑。提前感谢您的帮助。
发布于 2017-05-01 19:14:08
var gulp = require('gulp');
var browserSync = require('browser-sync').create(); //reloading while saving file
var php = require('gulp-connect-php'); //for PHP server选中此部分,您编写gulp,但您需要编写gulp.php,并且在调用任何文件名的位置,必须添加文件扩展名,然后在项目中调用此文件
https://stackoverflow.com/questions/43707388
复制相似问题