T
T
thebigbang2020-01-11 14:13:02
Flask
thebigbang, 2020-01-11 14:13:02

How to set up BrowserSync in Gulp that proxy Flask?

var browserSync = require("browser-sync").create();

var paths = {
    styles: {
        src: "static/sass/style.scss",
        dest: "static/css"
    }
}

function reload() {
    browserSync.reload();
}

function style() {
    return (
        gulp
            .src(paths.styles.src)
            // Initialize sourcemaps before compilation starts
            .pipe(sourcemaps.init())
            .pipe(sass())
            .on("error", sass.logError)
            // Use postcss with autoprefixer and compress the compiled file using cssnano
            .pipe(postcss([autoprefixer(), cssnano()]))
            // Now add/write the sourcemaps
            .pipe(sourcemaps.write())
            .pipe(gulp.dest(paths.styles.dest))
            .pipe(browserSync.stream())
    );
    reload();
}
 
function watch() {
    browserSync.init({
        // You can tell browserSync to use this directory and serve it as a mini-server
        proxy: "127.0.0.1:5003"
        // If you are already serving your website locally using something like apache
        // You can use the proxy setting to proxy that instead
        // proxy: "yourlocal.dev"
    });
    gulp.watch("static/sass/*.scss", style);
    gulp.watch("templates/*.html", reload);
}

var gulp = require("gulp"),
    sass = require("gulp-sass"),
    postcss = require("gulp-postcss"),
    autoprefixer = require("autoprefixer"),
    cssnano = require("cssnano"),
    sourcemaps = require("gulp-sourcemaps");
    

exports.watch = watch;
exports.style = style;

this is gulpfile.js .
Style works fine, when changing scss files it compiles and updates.
And when I update the template, the update works only once, the line appears
[14:04:53] Starting 'reload'...
[Browsersync] Reloading Browsers...
The page is updated, but then gulp stops responding to changes. Please tell me how to fix this. Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question