我正在寻找从咕噜到吞咽的过渡。但是,我没有找到一种方法来提供具有 livereload 支持的 PHP 文件,例如使用挂载的网关( https://www.npmjs.org/package/gateway )。有没有使用 gulp 任务运行/服务器 PHP 的插件?
问问题
2523 次
2 回答
1
几周前我问了完全相同的问题。我想在 Gulp 下启动一个原生 PHP 服务器,因为我比 Grunt 更喜欢语法。我还想使用 PHP 来包含其他 HTML 文件。:) 原来有一个“gulp-connect-php”插件,它的语法与“grunt-php”插件非常相似。
https://www.npmjs.com/package/gulp-connect-php
https://www.npmjs.com/package/grunt-php
这是我的 Gulp 代码:
var gulp = require('gulp'),
livereload = require('gulp-livereload'),
connectPHP = require('gulp-connect-php');
gulp.task('connect', function() {
connectPHP.server({
hostname: '0.0.0.0',
bin: 'C:/php/php.exe',
ini: 'C:/php/php.ini',
port: 8000,
base: 'dev',
livereload: true
});
});
我还设置了 exe 和 ini 文件位置。
如果您有兴趣,这是 Grunt 的代码:
php: {
watch: {
options: {
livereload: true,
bin: 'C:/php/php.exe',
ini: 'C:/php/php.ini',
base: '../development',
port: 8000
}
}
}
我希望它有帮助!
于 2014-12-11T16:24:26.920 回答
0
我最终将 gulp-connect-php 与 http-proxy 一起使用。最后,我的 php 服务任务如下所示:
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: '{ip address taken out}: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']);
});
于 2015-05-30T18:06:55.593 回答