这篇文章对于让 browsersync 与 PHP 站点一起工作非常有帮助。
这些是 Grunt 和 Gulp 的配置应该是什么样的(摘自文章)
咕噜声
您将需要grunt-php插件
grunt.loadNpmTasks('grunt-browser-sync');
grunt.loadNpmTasks('grunt-php');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.initConfig({
watch: {
php: {
files: ['app/**/*.php']
}
},
browserSync: {
dev: {
bsFiles: {
src: 'app/**/*.php'
},
options: {
proxy: '127.0.0.1:8010', //our PHP server
port: 8080, // our new port
open: true,
watchTask: true
}
}
},
php: {
dev: {
options: {
port: 8010,
base: 'path/to/root/folder'
}
}
}
});
grunt.registerTask('default', ['php', 'browserSync', 'watch']);
吞咽
您将需要gulp-connect-php插件
// Gulp 3.8 code... differs in 4.0
var gulp = require('gulp'),
php = require('gulp-connect-php'),
browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('php', function() {
php.server({ base: 'path/to/root/folder', port: 8010, keepalive: true});
});
gulp.task('browser-sync',['php'], function() {
browserSync({
proxy: '127.0.0.1:8010',
port: 8080,
open: true,
notify: false
});
});
gulp.task('default', ['browser-sync'], function () {
gulp.watch(['build/*.php'], [reload]);
});