How can I do to reload a symfony2 server with gulp?

Cristian Chaparro A.

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:

  1. Start my symfony2 server php app/console server:run
  2. Start my gulp file gulp and deploy the task watch that focus on reload every change on the code

CASE B:

For example

  1. Star my gulp file 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?

Cristian Chaparro A.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I do to reload a symfony2 server with gulp?

From Dev

Gulp/Symfony2: How can I avoid overwriting my js/css imports when cache busting?

From Dev

In Symfony2 how can I append a date to the assetic filenames

From Dev

How can I throw a 403 exception in Symfony2?

From Dev

How can I catch errors and exceptions in Symfony2/Silex?

From Dev

How can I get the action name in a Symfony2 controller?

From Dev

How can I dynamically set a parameter in Symfony2?

From Dev

How can I inject doctrine into Symfony2 service

From Dev

How can i show the first published demands in Symfony2 ?

From Dev

How can I create complex reports with PHP / Symfony2?

From Dev

How can I join multiple tables in symfony2?

From Dev

How can I load templates from subdirectories in Symfony2?

From Dev

How can I get the action name in a Symfony2 controller?

From Dev

How can I dynamically set a parameter in Symfony2?

From Dev

How can I create complex reports with PHP / Symfony2?

From Dev

how can I change the implementation of FlashBag messages in Symfony2

From Dev

In Symfony2 how can I append a date to the assetic filenames

From Dev

How can i restrict acces in my page? Symfony2

From Dev

How can I join multiple tables in symfony2?

From Dev

In Symfony2 routing, how do I setup an optional subdomain

From Dev

In Symfony2, how do I expire a user's account?

From Dev

How do I pass a value to Form Builder in Symfony2?

From Dev

How do I dependency inject PDO to a service in Symfony2?

From Dev

How do I configure $this->cwd for symfony2 framework

From Dev

How do I use a misc function in Symfony2?

From Dev

How do I get the short name of an entity in Symfony2?

From Dev

In Symfony2 routing, how do I setup an optional subdomain

From Dev

How do I dependency inject PDO to a service in Symfony2?

From Dev

How can I check if request was a POST or GET request in Symfony2 or Symfony3

Related Related

  1. 1

    How can I do to reload a symfony2 server with gulp?

  2. 2

    Gulp/Symfony2: How can I avoid overwriting my js/css imports when cache busting?

  3. 3

    In Symfony2 how can I append a date to the assetic filenames

  4. 4

    How can I throw a 403 exception in Symfony2?

  5. 5

    How can I catch errors and exceptions in Symfony2/Silex?

  6. 6

    How can I get the action name in a Symfony2 controller?

  7. 7

    How can I dynamically set a parameter in Symfony2?

  8. 8

    How can I inject doctrine into Symfony2 service

  9. 9

    How can i show the first published demands in Symfony2 ?

  10. 10

    How can I create complex reports with PHP / Symfony2?

  11. 11

    How can I join multiple tables in symfony2?

  12. 12

    How can I load templates from subdirectories in Symfony2?

  13. 13

    How can I get the action name in a Symfony2 controller?

  14. 14

    How can I dynamically set a parameter in Symfony2?

  15. 15

    How can I create complex reports with PHP / Symfony2?

  16. 16

    how can I change the implementation of FlashBag messages in Symfony2

  17. 17

    In Symfony2 how can I append a date to the assetic filenames

  18. 18

    How can i restrict acces in my page? Symfony2

  19. 19

    How can I join multiple tables in symfony2?

  20. 20

    In Symfony2 routing, how do I setup an optional subdomain

  21. 21

    In Symfony2, how do I expire a user's account?

  22. 22

    How do I pass a value to Form Builder in Symfony2?

  23. 23

    How do I dependency inject PDO to a service in Symfony2?

  24. 24

    How do I configure $this->cwd for symfony2 framework

  25. 25

    How do I use a misc function in Symfony2?

  26. 26

    How do I get the short name of an entity in Symfony2?

  27. 27

    In Symfony2 routing, how do I setup an optional subdomain

  28. 28

    How do I dependency inject PDO to a service in Symfony2?

  29. 29

    How can I check if request was a POST or GET request in Symfony2 or Symfony3

HotTag

Archive