I'd like to adapt this code to serve PHP files. I have MAMP running a local server but I can't figure out how this code works in order to make the necessary changes. I know that Node server won't interpret PHP files, but I'm confused about this architecture using serve-static
and serve-index
because apparently I can't just use a local file path inside MAMP's localhost to serve those files, right? I also wonder why it needs 2 ports (9000 and 35729).
gulp.task('connect', ['styles'], function () {
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');
var app = require('connect')()
.use(require('connect-livereload')({port: 35729}))
.use(serveStatic('.tmp'))
.use(serveStatic('app'))
.use('/bower_components', serveStatic('bower_components'))
.use(serveIndex('app'));
require('http').createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
});
gulp.task('serve', ['connect', 'watch'], function () {
require('opn')('http://localhost:9000');
});
gulp.task('watch', ['connect'], function () {
$.livereload.listen();
// watch for changes
gulp.watch([
'app/*.php',
'.tmp/styles/**/*.css',
'app/scripts/**/*.js',
'app/images/**/*'
]).on('change', $.livereload.changed);
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('bower.json', ['wiredep']);
});
I basically want to use PHP for templating (footer, header, etc) for a website, just like this person posted here.
I have the feeling that people don't do this anymore though, so any suggestions for front-end development with static assets and templates (for later adapting to WordPress or another PHP-based CMS) are welcome.
EDIT
Please read this: Gulp-webapp running BrowserSync and PHP