S.Hagvin
S.Hagvin

Reputation: 85

Gulp reload doesn't work

I want use gulp reload on my workflow, but I have trouble with it. When I started via "gulp" command in command line I have server connection, but when I go to my browser there is the massege "Cannot GET /" What is it, and how can I solve this problem? Help please.

I have next gulpfile.js:

  /**
 * Created by adm on 4/24/2016.
 */
var gulp = require('gulp'),
    rename = require('gulp-rename'),
    minifyCSS = require('gulp-minify-css'),
    notify = require("gulp-notify"),
    livereload = require('gulp-livereload'),
    connect = require('gulp-connect');

/*----------Local Server connect----------*/
gulp.task('connect', function() {
    connect.server({
        root: 'traning_js_skils',
        livereload: true
    });
});

/*----------HTML----------*/
gulp.task('html', function () {
    gulp.src('./src/index.html')
        .pipe(connect.reload());
});

/*----------CSS----------*/
gulp.task('css', function() {
    return gulp.src('css/*.css')
        .pipe(minifyCSS({keepBreaks:true}))
        .pipe(rename('common.min.css'))
        .pipe(gulp.dest('testfiles/'))
        .pipe(livereload());
        /*.pipe(connect.reload());*/
        /*.pipe(notify('Done!'))*/
});

/*----------Watch----------*/
gulp.task('watch', function () {
    livereload();
    gulp.watch('css/*.css', ['css']);
    gulp.watch('index.html', ['html']);
});

gulp.task('default', ['css', 'watch', 'connect']);

Here is my structure of project: enter image description here

Upvotes: 2

Views: 1741

Answers (1)

rick
rick

Reputation: 1895

I put the full answere here:

so for the root.

If your index.html file is the one in the main directory. set the root config to ./

connect.server({
        root: './',
        livereload: true
    });

For the reloading.

I don't use livereload but in the doc I can see this

gulp.task('less', function() {
  gulp.src('less/*.less')
    .pipe(less())
    .pipe(gulp.dest('css'))
    .pipe(livereload());
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch('less/*.less', ['less']);
});

can be that you're missing the .listen()

Upvotes: 4

Related Questions