2

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

S.Hagvin
  • 85
  • 1
  • 11
  • can you add a screenshot of your project directory structure please? – rick Apr 25 '16 at 13:54
  • Of course I can. Look above, I have added structure of my product. If it is important my project worked on angularjs and before I had used node-static server for get json data. Maybe it is some conflict between node-static and gulp connect? – S.Hagvin Apr 25 '16 at 14:29
  • If the index.html you want to serve is the one in the root the only strage thing I see is the root: 'traning_js_skils' it's possible that livereload is searching the directory traning_js_skils/traning_js_skils? try to put "./" in the root config – rick Apr 25 '16 at 14:35
  • Thank you great! Your tip has changed my situation the error "Cannot GET /" disappeared. I new in using gulp that is why I make such error. But my index page still doesn't reload when I change my css file. What the reason can be? – S.Hagvin Apr 25 '16 at 15:15

1 Answers1

4

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()

rick
  • 1,869
  • 13
  • 22