How to update in browser using gulp

I have an application in iis, this application is made in angularjs and webapi C # 2.0, I would like to create a task that updates the browser as soon as I save any js file.

Gulp Version: 3.9.1

gulp.task('livereload', function () {
    gulp.watch(config.files.js);
});
+4
source share
1 answer

gulp-livereload

A lightweight gulp oven plugin that will be used with a hedge extension to increase or middleware for cookies .

Easy setup:

var gulp = require('gulp'),
    less = require('gulp-less'),
    livereload = require('gulp-livereload');

gulp.task('less', function() {
  gulp.src('less/*.less')
    .pipe(less())
    .pipe(gulp.dest('dist'))
    .pipe(livereload());
});

gulp.task('watch', function() {
  livereload.listen();
  gulp.watch('less/*.less', ['less']);
});

Browsersync

Browsersync Gulp, ! require , API options.

, .

Browsersync, , . Browsersync CSS, - , .stream() gulp.dest.

var gulp = require('gulp'),
    browserSync = require('browser-sync').create(),
    sass = require('gulp-sass');

// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {

    browserSync.init({
        server: "./app"
        // or
        // proxy: 'yourserver.dev'
    });

    gulp.watch("app/scss/*.scss", ['sass']);
    gulp.watch("app/*.html").on('change', browserSync.reload);
});

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src("app/scss/*.scss")
        .pipe(sass())
        .pipe(gulp.dest("app/css"))
        .pipe(browserSync.stream());
});

gulp.task('default', ['serve']);

:

// ...
var reload = browserSync.reload;

// Save a reference to the `reload` method

// Watch scss AND html files, doing different things with each.
gulp.task('serve', function () {

    // Serve files from the root of this project
    browserSync.init({/* ... */});

    gulp.watch("*.html").on("change", reload);
});

Browsersync ?

, . , .

+6

Source: https://habr.com/ru/post/1674837/


All Articles