我想在PHP中使用Browsersync,但我似乎无法让它正常工作。
目前我正在使用Gulp。是否可以在XAMPP/MAMP中使用浏览器同步,或者使用Gulp插件来读取.php
文件?
发布于 2018-03-08 00:53:36
使用gulp connect-php
npm install --save-dev gulp-connect-php
然后设置你的gulpfile.js
var gulp = require('gulp'),
connect = require('gulp-connect-php'),
browserSync = require('browser-sync');
gulp.task('connect-sync', function() {
connect.server({}, function (){
browserSync({
proxy: '127.0.0.1:8000'
});
});
gulp.watch('**/*.php').on('change', function () {
browserSync.reload();
});
});
请参阅文档https://www.npmjs.com/package/gulp-connect-php
这里也有一个很好的教程,https://phpocean.com/tutorials/front-end/automate-your-workflow-with-gulp-part-3-live-reloading/23
发布于 2021-10-20 13:12:57
现在,在使用外部服务器时,浏览器同步中提供了proxy
选项。
配置文档:https://browsersync.io/docs/options#option-proxy
// Using a vhost-based url
proxy: "local.dev"
// Using a localhost address with a port
proxy: "localhost:8888"
// Using localhost sub directories
proxy: "localhost/site1"
命令行:https://browsersync.io/docs/command-line#start
browser-sync start --proxy "localhost:8080" --files "**/*"
https://stackoverflow.com/questions/42892537
复制相似问题