【问题标题】:How to fix the 'Cannot GET/' error with BrowseSync?如何使用 BrowseSync 修复“Cannot GET/”错误?
【发布时间】:2019-04-23 14:00:53
【问题描述】:

我正在使用 Gulp 设置,它将监视我的 HTML、Sass 和文件。下面的错误如何解决?

无法获取/

这是我的代码:

//Watch Files
htmlWatchFiles = './src/html/main/*.html';

//Input files
//  File for gulp-sass compiler
var inputScssFile = './src/stylesheets/**/*.scss'

function sassCompiler() {
    return gulp.src(inputScssFile)
      .pipe(sass())
      .pipe(autoPrefixer())
      .pipe(dest('./src/stylesheets/output'))
      .pipe(browserSync.stream());
}

这是我要观看的功能:

function toBrowseSync(){
    browserSync.init({
        server: {
            baseDir: "src/",
            index:"./src/html/main/index/html"
        }
    });
    gulp.watch(inputScssFile,sassCompiler);
    gulp.watch(htmlWatchFiles).on('change', browserSync.reload);
}

exports.default = series(sassCompiler,toBrowseSync);

【问题讨论】:

标签: gulp gulp-watch gulp-sass


【解决方案1】:

对于 BrowserSync 配置,在 index 属性中使用的路径应该是相对于所使用的 baseDir 的。文档here 也在代码注释中提到了这一点。

browserSync.init({
    server: {
        baseDir: "src/",
        index:"html/main/index.html"
    }
});

【讨论】:

    猜你喜欢
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 2020-05-02
    • 1970-01-01
    • 2021-05-22
    • 2021-10-31
    • 2021-10-24
    相关资源
    最近更新 更多