【问题标题】:Browser sync reloading not working浏览器同步重新加载不起作用
【发布时间】:2023-03-14 01:52:02
【问题描述】:

我正在尝试使用 gulp 配置浏览器同步,我想查看我的 scss 文件并将它们编译并保存在一个名为 dist 的文件夹中,当进行更改时,我还想在此过程完成后重新加载我的浏览器。 到目前为止,我成功地在新窗口中观看、编译和加载结果,但是当 scss 文件中进行进一步更改时,我无法刷新浏览器窗口。我在这里做错了什么?我也想知道这是否是正确的方法。

这是我的 gulpfile.js

'use strict';
    var gulp = require('gulp'),
        scss = require('gulp-sass'),
        maps = require('gulp-sourcemaps'),
        browsersync = require("browser-sync");




gulp.task("ScssCompiler",function(){
    gulp.src("scss/style.scss")  
    .pipe(maps.init())
    .pipe(scss()) 
    .pipe(maps.write('./'))
    .pipe(gulp.dest('dist')); 
    console.log("entered ScssCompiler");
});

gulp.task("sass-watch",["ScssCompiler"],browsersync.reload);


gulp.task("watchsass",function(){
    browsersync({
        server:{
            baseDir:'./',
        }
    });
    gulp.watch(['scss/*.scss'],['sass-watch']);
    console.log("entered watchsass");
});

gulp.task("build",['watchsass'],function(){
    console.log("entered build");
});

gulp.task("default",['build'],function(){

});

【问题讨论】:

    标签: gulp browser-sync gulp-watch gulp-sass gulp-browser-sync


    【解决方案1】:

    你可以看看我的代码: 解决所有问题。

    https://github.com/krmao/template/blob/gulp/build-script/Build.js

    【讨论】:

    • 感谢您的评论,但是那里有很多东西对我的项目没有用处?
    • @ShamseerAhammed 时间太长了,我现在忘记了...对不起
    猜你喜欢
    • 1970-01-01
    • 2023-04-09
    • 2015-09-11
    • 2017-11-08
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-25
    相关资源
    最近更新 更多