0
尝试设置yo webapp以使用PHP服务器而不是HTML。使用PHP设置Yeoman Webapp
我试着按照这个答案的例子没有成功。 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
这又如何解决?我甚至不介意使用MAMP,我已经在端口8888上运行
它的工作原理。我不得不在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不是一个函数...' –