简体   繁体   English

我该如何用gulp重新加载symfony2服务器?

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

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, 我想自动重新加载我的服务器symfony2,以便在对gulp进行一些更改时实时查看html页面上的更改,

CASE A: 案例A:

for example: 例如:

  1. Start my symfony2 server php app/console server:run 启动我的symfony2服务器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 启动我的gulp文件gulp并部署任务监视程序,该监视程序专注于重新加载代码上的每个更改

CASE B: 案例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. 星我一饮而尽文件gulp从我一饮而尽文件,在这种情况下设置了Symfony2的服务器并启动它,当我调用命令一饮而尽,并触发专注于relod上的代码的每一个变化表任务。

Test 1: gulp-connect-php 测试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 失败的原因是,当我运行此简单配置时,由于在当前文件夹上部署服务器,因此没有部署symfony2服务器,因此无法正常工作,我得到了以下信息

127.0.0.1:55669 [404]: / - No such file or directory

Test 2: gulp-connect 测试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 测试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: 1.设置您的gulp文件:

'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: 2.在您要进行更改监视的页面中,必须输入以下内容:

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 来源: 将Grunt / Gulp和Livereload集成到服务PHP / Zend的现有Apache服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM