1

I am learning the front-end build system currently gulp, i want to use brower-sync and the problem is when it brings up the browser it will not display my html file and it will say "Cannot GET /" error in the browser window. This is my index.js code. Help me

Thanks :)


import gulp from 'gulp';
import rename from 'gulp-rename'; 

import sass from 'gulp-sass';
import twig from 'gulp-twig';

import browserSync from 'browser-sync';

gulp.task('style', () => {
    console.log('execute sass file');

    return gulp.src('src/assets/scss/styles.scss')
        .pipe(rename('css/styles.css'))
        .pipe(gulp.dest('dist'));
});

gulp.task('index', () => {
    console.log('execute twig');

    return gulp.src('src/markup/index.twig')
    .pipe(rename('html/index.html'))
    .pipe(gulp.dest('dist/html'))
});


gulp.task('twig', function() {

    return gulp.src('src/markup/*.twig')
    .pipe(twig())
    .pipe(gulp.dest('dist/html'))
    .pipe(browserSync.reload({
        stream: true
    }))
});

gulp.task('sass', function () {

    return gulp.src('src/assets/scss/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('dist/css'))
    .pipe(browserSync.reload({
        stream: true
    }))
});

gulp.task('watch', function(done) {
    gulp.watch('src/assets/scss/**/*.scss', gulp.task('default'));
    gulp.watch('src/markup/index.twig', gulp.task('twig'));
    console.log('task twig and sass works');
    done();
});

gulp.task('browser-sync', () => {
    browserSync.init({
        server: {
            baseDir: 'dist/',
            browser:"google chrome",
            open: true,
        }
    });
});

gulp.task('start', gulp.parallel('browser-sync','twig', 'sass', 'watch'));


  • Might be a duplicate: [gulp + browser-sync Cannot GET / error](https://stackoverflow.com/questions/36991586/gulp-browser-sync-cannot-get-error/42974666#42974666) – lofihelsinki Mar 28 '19 at 13:32
  • Do you have an `index.html` in your `dist` directory? – d-h-e Mar 28 '19 at 13:36
  • Yes, i have, my Folder Structure is : src fold with : - assets --> scss --> style.scss - markup --> index.twig dist fold with: - css --> style.css - html --> index.html –  Mar 28 '19 at 13:47
  • @RaquelFiore I think your baseDir should be -> `baseDir: 'dist/html/'` if your index.html is in this html subfolder – d-h-e Mar 28 '19 at 14:08
  • 1
    Thanks !! Now worksss !! –  Mar 28 '19 at 14:14

0 Answers0