gulp + browser-sync Cannot GET / error

前端 未结 8 2531
悲哀的现实
悲哀的现实 2021-02-15 12:40

I am learning the front-end build system currently gulp, i want to use brower-sync and the problem is it is not throwing an error in the commad line but instead when it brings

8条回答
  •  醉酒成梦
    2021-02-15 13:00

    I solved my "Cannot GET" errors in browser-sync by always pointing to a .html file in code, or by having a folder structure ending with and index.html

    About 
    About 
    About 
    

    My Gulp file for reference (using browser-sync with jekyll, so everything is in the ./_site folder, and the gulpfile is in ./)

    var gulp = require('gulp');
    var shell = require('gulp-shell');
    var browserSync = require('browser-sync').create();
    
    gulp.task('build', shell.task(['jekyll build --watch']));
    
    // serving blog with Browsersync
    gulp.task('serve', function () {
        browserSync.init(
            {
                server: {baseDir: '_site/'}
            }
        );
    
        // Reloads page when some of the already built files changed:
        gulp.watch('_site/**/*.*').on('change', browserSync.reload);
    });
    
    gulp.task('default', ['build', 'serve']);
    

    Hope it helps.

    Michelangelo

提交回复
热议问题