正在尝试将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
发布于 2016-09-06 03:32:20
我好像错过了安装http-proxy的关键部分,我以为我之前已经安装过了。
这里有一个让PHP与最流行的yeoman生成器,生成器webapp一起工作的愚蠢指南,非常感谢TobyG。
npm install http-proxy --savenpm install --save-dev gulp-connect-php将这两个函数添加到gulpfile.js的顶部
const connect = require('gulp-connect-php');
const httpProxy = require('http-proxy');将此附加任务添加到gulpfile.js
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']);
});https://stackoverflow.com/questions/39333190
复制相似问题