使用PHP设置Yeoman Webapp
正在尝试将yo webapp设置为使用PHP服务器而不是HTML 我试着以身作则地遵循这个答案,但没有成功。 我加入了我的项目使用PHP设置Yeoman Webapp,php,generator,yeoman,browser-sync,Php,Generator,Yeoman,Browser Sync,正在尝试将yo webapp设置为使用PHP服务器而不是HTML 我试着以身作则地遵循这个答案,但没有成功。 我加入了我的项目 // 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 () { c
// 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']);
});
运行吞下php服务
PHP 5.5.36 Development Server started [etc…]
Listening on http://127.0.0.1:9001
然而,并非没有错误:
ReferenceError: httpProxy is not defined
如何解决这个问题?我甚至不介意使用我已经在8888端口上运行的MAMP,似乎我错过了安装http代理的一个重要部分,我认为我以前已经安装了http代理 下面是一个让PHP与最流行的yeoman生成器generator webapp一起工作的白痴指南,非常感谢 安装 安装 将这两个函数添加到gulpfile.js的顶部 将此附加任务添加到gulpfile.js
它起作用了。我不得不在gulpfile中更改html任务中的一些位:从
return gulp.src('app/*.html')
到return gulp.src(['app/*.html','app/*.php'))
为了将从php文件调用的js和css编译到dist文件夹,您还必须在wiredep任务中进行相同的编辑。如果您已将generator webapp更新为2.3.2版,则需要在建议的代码中额外更改一行。将browserSync({…
更改为browserSync.init({
以避免错误browserSync不是一个函数…
npm install http-proxy --save
npm install --save-dev gulp-connect-php
const connect = require('gulp-connect-php');
const httpProxy = require('http-proxy');
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']);
});