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

问题描述

我正在尝试让 gulp 与 livereload 一起工作.Gulp 无法控制网络服务器本身(实际的网络应用程序是一个 php 站点.当我在服务器上运行 nmap 时,我看不到 livereload 工作,并且 chrome 扩展名表示同样的事情.

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.

这是我的 gulp 任务:

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)

推荐答案

这里有一个简单基于connect服务器和connect-livereloadgulp-livereload插件测试 livereload解决方案:

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);
});

编辑.

我错过了 PHP 部分.我没有使用它,但这可能会对您有所帮助:https://github.com/micahblu/gulp-connect-php

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 服务器未启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 11:51