问题描述
我有一个使用 Gulp 和 browserSync 的 Bootstrap 主题,我需要对其进行调整才能使用 PHP 文件。 Gulpfile 中最初的 browserSync init 函数如下:
const browsersync = require('browser-sync').create();
function browserSync(done) {
browsersync.init({
files: "./*.html",startPath: config.startPath,server: {
baseDir: [paths.src.tmp.dir,paths.src.base.dir,paths.root],middleware: function (req,res,next) {
if (/\.json|\.txt|\.html/.test(req.url) && req.method.toupperCase() == 'POST') {
req.method = 'GET';
}
url = req.url;
var index = 0;
index = req.url.indexOf('?');
if (index == -1){
index = req.url.indexOf('#');
}
if (index != -1){
url = req.url.substring(0,index);
}
var filename = __dirname.replace('gulpfiles','') + paths.src.tmp.dir.replace('./','') + url;
if (url.split('.').pop() === 'html') {
fileInclude(() => {
if (fs.existsSync(filename)) {
var html = fs.readFileSync(filename,'utf8');
res.end(html)
} else {
res.end('Oops,page not found.')
}
})
} else {
next();
}
}
}
});
done();
}
到目前为止我已经安装了 gulp-connect-PHP 并修改了这个功能:
const browsersync = require('browser-sync').create();
const PHP = require('gulp-connect-PHP');
function browserSync(done) {
PHP.server({
base: paths.src.base.dir,port: 5000,keepalive: true
},function(){
browsersync.init({
files: "./*.html,./*.PHP",proxy: '127.0.0.1:5000'
});
})
done();
}
它正在加载页面,但 CSS/JS 未正确提供服务,我假设这是因为我在该中间件功能中缺少一些关键信息。 browsersync 不会同时使用服务器和代理选项,因此我需要将此中间件功能重新定位到我的新 browserSync init 中的某个位置,但我终生无法弄清楚它在做什么或将它放在哪里。任何帮助将非常感激。谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)