9

我想将 Browsersync 与 PHP 一起使用,但我似乎无法让它正常工作。

目前我正在使用 Gulp。是否可以将 Browsersync 与 XAMPP/MAMP 一起使用,或者使用 Gulp 插件来读取.php文件?

4

3 回答 3

5

使用 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

于 2018-03-07T16:53:36.257 回答
4

我有几天同样的情况,直到我发现它发生是因为我没有正确关闭我的 html 输出。BrowserSync 需要在重新加载浏览器之前包含一些 javascript 文本。如果htmlbody标记未关闭不存在,则 BrowserSync无处包含脚本。

于 2018-01-04T15:59:16.183 回答
0

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 "**/*"
于 2021-10-20T13:12:56.627 回答