I would like to reload automatically my server symfony2 to see in real time the changes on my html pages, when I do some change with gulp,
CASE A:
for example:
php app/console server:run
gulp
and deploy the task watch that focus on reload every change on the codeCASE B:
For example
gulp
, in this case setup the symfony2 server from my gulp file and start it when I call the command gulp, and trigger the watch task that focus on relod every change on the code.Test 1:gulp-connect-php
var connect = require('gulp-connect-php');
gulp.task('connect', function() {
connect.server();
});
/** here, please don't say me use assets, is a special requirement and is an example*/
gulp.task('productstemplates',function(){
gulp.src( './appjs/products/templates/**/*.html')
.pipe( gulp.dest( './web/products/') )
.pipe( connect.reload() );
});
/** another task to watch the changes over css,less,html pages, php controllers ..*/
gulp.task('default', ['connect','another_task']);
What fails here, when I run this simple configurations not works because this deploy a server over the current folder, then symfony2 server is not deployed, and I get the following
127.0.0.1:55669 [404]: / - No such file or directory
Test 2: gulp-connect
'use strict';
var gulp = require('gulp');
var connect = require('gulp-connect');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var livereload = require('gulp-livereload');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('appjs',function(){
gulp.src( './appjs/app.js')
.pipe( gulp.dest('./web/') );
});
gulp.task('app-index',function(){
console.log("chaning something on index.html... ");
gulp.src( './appjs/index.html')
.pipe( gulp.dest( './web/') )
.pipe( connect.reload() );
});
gulp.task('watch',function(){
gulp.watch( ['./appjs/app.js'], ['appjs']);
gulp.watch( ['./appjs/index.html'], ['app-index']);
});
var tasks = [ 'appjs','app-index','watch'];
gulp.task('default',tasks );
Test 3: livereload
'use strict';
var gulp = require('gulp');
var connect = require('gulp-connect');
var livereload = require('gulp-livereload');
gulp.task('appjs',function(){
gulp.src( './appjs/app.js')
.pipe( gulp.dest('./web/') );
});
gulp.task('app-index',function(){
console.log('chaning something on index.html...');
gulp.src( './appjs/index.html')
.pipe( gulp.dest( './web/') )
.pipe( livereload({ start: true }) );
});
gulp.task('watch',function(){
livereload.listen();
gulp.watch( ['./appjs/app.js'], ['appjs']);
gulp.watch( ['./appjs/index.html'], ['app-index']);
});
var tasks = [ 'appjs','app-index','watch'];
gulp.task('default',tasks );
then I don't know how to do the rigth setup.
any body can help me to do the right setup or show me a right way to do it?
Afeter some atempts I got it, so the following is the code to auto refresh my pages when some change is detect
1. Settup your gulp file:
'use strict';
var gulp = require('gulp');
var livereload = require('gulp-livereload');
gulp.task('appjs',function(){
gulp.src( './appjs/app.js')
.pipe( gulp.dest('./web/') );
});
gulp.task('app-index',function(){
console.log('chaning something on index.html...');
gulp.src( './appjs/index.html')
.pipe( gulp.dest( './web/') )
.pipe( livereload({ start: true }) );
});
gulp.task('watch',function(){
livereload.listen();
gulp.watch( ['./appjs/app.js'], ['appjs']);
gulp.watch( ['./appjs/index.html'], ['app-index']);
});
var tasks = [ 'appjs','app-index','watch'];
gulp.task('default',tasks );
2. in the page that you wanna do a change monitoring you must put it:
The following code is dev mode.
<script type="text/javascript">document.write('<script src="//localhost:35729/livereload.js?snipver=1" type="text/javascript"><\/script>')</script>
Source: Integrating Grunt/Gulp and Livereload to existing Apache server serving PHP/Zend