简体   繁体   English

在Gulp.js服务器上设置LiveReload

[英]Setting up LiveReload on Gulp.js server

I'm trying to set up my build system but having some trouble getting LiveReload to to work with the files I need. 我正在尝试设置构建系统,但在使LiveReload能够处理所需文件时遇到了一些麻烦。 I have included my current gulpfile below. 我在下面包括了我当前的gulpfile。 When I run my gulp command, I know that the server is running on 'localhost:35729/'. 当我运行gulp命令时,我知道服务器正在'localhost:35729 /'上运行。 However when I go to the address in my browser I receive this message: 但是,当我在浏览器中转到该地址时,会收到以下消息:

{"tinylr":"Welcome","version":"0.1.6"}

Basically what I need to know is how I can get my index page to display here rather than this message, as the Chrome LiveReload extension will not reload the version of my index page that is just sitting in my offline directory. 基本上,我需要知道的是如何使索引页面显示在此处而不是显示此消息,因为Chrome LiveReload扩展程序不会重新加载仅位于脱机目录中的索引页面的版本。

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var sass = require('gulp-ruby-sass');
var livereload = require('gulp-livereload');

function errorLog(error) {
    console.error.bind(error);
    this.emit('end');
}

// Scripts Task
// Uglifies
gulp.task('scripts', function(){
    gulp.src('js/*.js')
    .pipe(uglify())
    .on('error', errorLog)
    .pipe(gulp.dest('minjs'))
});

//SASS Task
//Compiles SASS
gulp.task('sass', function(){
    return sass('scss/*.scss', { style: 'compressed' })
    .on('error', errorLog)
    .pipe(gulp.dest('./css'))
    .pipe(livereload());
});

// Watch Task
// Watches JS and CSS
gulp.task('watch', function(){
     livereload.listen();
     gulp.watch('js/*.js', ['scripts']);
     gulp.watch('scss/*.scss', ['sass']);
});

gulp.task('default', ['scripts', 'sass', 'watch',]);

Yes in the end I did. 是的,最后我做到了。 Basically the LiveReload Chrome application won't watch offline files for changes (ie files opened straight from their directory). 基本上,LiveReload Chrome应用程序不会监视脱机文件的更改(即直接从其目录打开的文件)。 My solution to this was to configure a MAMP web server with my sites directory as the home directory. 我的解决方案是将MAMP Web服务器配置为我的站点目录作为主目录。 Then I was able to open the index page on the web server instead, and click the LiveReload Chrome button, which started watching for changes. 然后,我可以打开Web服务器上的索引页面,然后单击LiveReload Chrome按钮,该按钮开始监视更改。

I don't think setting up a MAMP server is necessarily a requisite solution, this was just the way I handled it, as I can now also test the site for mobile devices. 我不认为设置MAMP服务器不一定是必不可少的解决方案,这只是我的处理方式,因为我现在还可以针对移动设备测试该站点。

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

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