【发布时间】:2016-09-05 14:54:48
【问题描述】:
尝试设置 yo webapp 以使用 PHP 服务器而不是 HTML。
我尝试通过示例遵循此答案,但没有成功。 Gulp-webapp running BrowserSync and PHP
我将gulp-connect-php 添加到我的项目中。
// Towards the top of my gulpfile, added:
const connect = require('gulp-connect-php');
// Added the following task below:
gulp.task('php-serve', ['styles', 'fonts'], function () {
connect.server({
port: 9001,
base: 'app',
open: false
});
var proxy = httpProxy.createProxyServer({});
browserSync({
notify: false,
port : 9000,
server: {
baseDir : ['.tmp', 'app'],
routes : {
'/bower_components': 'bower_components'
},
middleware: function (req, res, next) {
var url = req.url;
if (!url.match(/^\/(styles|fonts|bower_components)\//)) {
proxy.web(req, res, { target: 'http://127.0.0.1:9001' });
} else {
next();
}
}
}
});
// watch for changes
gulp.watch([
'app/*.html',
'app/*.php',
'app/scripts/**/*.js',
'app/images/**/*',
'.tmp/fonts/**/*'
]).on('change', reload);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/fonts/**/*', ['fonts']);
gulp.watch('bower.json', ['wiredep', 'fonts']);
});
跑gulp php-serve
PHP 5.5.36 Development Server started [etc…]
Listening on http://127.0.0.1:9001
但是,并非没有错误:
ReferenceError: httpProxy is not defined
如何解决?我什至不介意使用我已经在 8888 端口上运行的 MAMP
【问题讨论】:
标签: php generator yeoman browser-sync