gulp + browser-sync Cannot GET / error

前端 未结 8 2506
悲哀的现实
悲哀的现实 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:17

    Is there an index.html file in your ./public/ folder? If not, you need to tell browserSync what is your start page. You can also get browserSync to show the listing of the base directory, see update below.

    You could also try to use public without the leading dot.

    Edit: The startPath config directive does not seem to work, use index instead

    ...
    gulp.task('browser-sync', function() {
       browserSync({
         server: {
            baseDir: "public/",
            index: "my-start-page.html"
         }
       });
    });
    ...
    

    Update: Actually you can get directory listing with browserSync. That way it would show a list of files in public, not the Cannot Get error

    ...
    gulp.task('browser-sync', function() {
       browserSync({
         server: {
            baseDir: "public/",
            directory: true
         }
       });
    });
    ...
    

提交回复
热议问题