本文介绍了Gulp Livereload服务器无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用livereload进行大量的工作。 Gulp不能控制Web服务器本身(实际的Web应用程序是一个PHP站点,当我在服务器上运行nmap时,我没有看到livereload正在工作,而且Chrome扩展指出了同样的事情。 b

以下是我的大吞吐任务:

  gulp = require'gulp'
{livereload } = require('gulp-load-plugins')()

gulp.task'watch',['styles'], - >
livereload.listen()

gulp.watch'./public/include/less/**/*.less',['styles']
gulp.watch('./ public / include / css / ** / * .css')。on('change',livereload.changed)


解决方案

以下是基于在连接服务器和 connect-livereload gulp-livereload 插件:

  
var gulp = require('gulp');
var co nnect = require('connect');
var connectLivereload = require('connect-livereload');
var opn = require('opn');
var gulpLivereload = require('gulp-livereload');

var config = {
rootDir:__dirname,
servingPort:8080,

//您要观看的实时重新加载更改的文件
filesToWatch:['*。{html,css,js}','!Gulpfile.js']
}

//默认任务 - 运行`gulp时调用`从CLI
gulp.task('default',['watch','serve']);
$ b gulp.task('watch',['connect'],function(){
gulpLivereload.listen();
gulp.watch(config.filesToWatch,function(文件){
gulp.src(file.path)
.pipe(gulpLivereload());
});
});
$ b gulp.task('serve',['connect'],function(){
return opn('http:// localhost:'+ config.servingPort);
});

gulp.task('connect',function(){
return connect()
.use(connectLivereload())
.use(connect.static config.rootDir))
.listen(config.servingPort);
});






编辑。



我错过了PHP部分。
我没有使用它,但这可能会帮助你:


I am attempting to get gulp working with livereload. Gulp is not in control of the webserver itself (the actual web app is a php site. When I run nmap on the server I don't see livereload working, and the chrome extension indicates the same thing.

Here is my gulp task:

gulp = require 'gulp'
{livereload} = require('gulp-load-plugins')()

gulp.task 'watch', ['styles'], ->
    livereload.listen()

    gulp.watch './public/include/less/**/*.less', ['styles']
    gulp.watch('./public/include/css/**/*.css').on('change', livereload.changed)
解决方案

Here is a simple and tested livereload solution based on connect server and connect-livereload and gulp-livereload plugins:


var gulp = require('gulp');
var connect = require('connect');
var connectLivereload = require('connect-livereload');
var opn = require('opn');
var gulpLivereload = require('gulp-livereload');

var config = {
    rootDir: __dirname,
    servingPort: 8080,

    // the files you want to watch for changes for live reload
    filesToWatch: ['*.{html,css,js}', '!Gulpfile.js']
}

// The default task - called when you run `gulp` from CLI
gulp.task('default', ['watch', 'serve']);

gulp.task('watch', ['connect'], function () {
  gulpLivereload.listen();
  gulp.watch(config.filesToWatch, function(file) {
    gulp.src(file.path)
      .pipe(gulpLivereload());
  });
});

gulp.task('serve', ['connect'], function () {
  return opn('http://localhost:' + config.servingPort);
});

gulp.task('connect', function(){
  return connect()
    .use(connectLivereload())
    .use(connect.static(config.rootDir))
    .listen(config.servingPort);
});


EDIT.

I missed the PHP part.I haven't worked with it but this might help you:https://github.com/micahblu/gulp-connect-php

这篇关于Gulp Livereload服务器无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 02:03