Livereload feature does not seem to be functioning properly with Chrome browser

I'm currently working on setting up the livereload server, but I haven't been able to see the message

Live reload server listening on: <port_number>
, similar to what was shown in this video. Whenever I make changes to my files, the console acknowledges that the file has been reloaded. I have also installed the Chrome extension. Can anyone point out what I might be missing? Thank you.

gulpfile.js

'use strict';

// gulp included 
var gulp = require('gulp'),
    gutil = require('gulp-util');

// necessary plug-ins
var autoprefix = require('gulp-autoprefixer'),
    changed = require('gulp-changed'),
    concat = require('gulp-concat'),
    http = require('http'),
    imagemin = require('gulp-imagemin'),
    jshint = require('gulp-jshint'),
    livereload = require('gulp-livereload'),
    minifyCSS = require('gulp-minify-css'),
    minifyHTML = require('gulp-minify-html'),
    sass = require('gulp-sass'),
    st = require('st'),
    stripDebug = require('gulp-strip-debug'),
    uglify = require('gulp-uglify');

gulp.task('build-css', function() {
  return gulp.src('src/scss/**/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('dist/styles'));
});

// minifying new or edited HTML pages
gulp.task('htmlpage', function() {
  var htmlSrc = './src/*.html',
      htmlDst = './dist';

  return gulp.src(htmlSrc)
    .pipe(changed(htmlDst))
    .pipe(minifyHTML())
    .pipe(gulp.dest(htmlDst));
});

// minifying new images
gulp.task('imagemin', function() {
  var imgSrc = './src/images/**/*',
      imgDst = './dist/images';

  return gulp.src(imgSrc)
    .pipe(changed(imgDst))
    .pipe(imagemin())
    .pipe(gulp.dest(imgDst));
});

// JS hint task
gulp.task('jshint', function() {
  return gulp.src('./src/scripts/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

// JS concatenation, debugging removal and minification
gulp.task('scripts', function() {
  return gulp.src(['./src/scripts/lib.js','./src/scripts/*.js'])
    .pipe(concat('script.js'))
    .pipe(stripDebug())
    .pipe(uglify())
    .pipe(gulp.dest('./dist/scripts/'));
});

gulp.task('server', function(done) {
  http.createServer(
    st({
      path: __dirname + '/dist', 
      index: 'index.html', 
      cache: false
    })
  ).listen(8080, done);
});

// CSS concatenation, auto-prefixing and minification
gulp.task('styles', function() {
  return gulp.src(['./src/styles/*.css'])
    .pipe(concat('styles.css'))
    .pipe(autoprefix('last 2 versions'))
    .pipe(minifyCSS())
    .pipe(gulp.dest('./dist/styles/'));
});

gulp.task('watch', ['server'], function() {
  livereload.listen({
    basePath: 'dist'
  });

  // monitoring HTML changes
  gulp.watch('./src/*.html', ['htmlpage']).on('change', livereload.changed);

  // monitoring JS changes
  gulp.watch('./src/scripts/*.js', ['jshint', 'scripts']).on('change', livereload.changed);

  // monitoring CSS changes
  gulp.watch('./src/styles/*.css', ['styles']).on('change', livereload.changed);

  gulp.watch('src/scripts/**/*.js', ['jshint']).on('change', livereload.changed);
  gulp.watch('src/styles/scss/**/*.scss', ['build-css']).on('change', livereload.changed);
});

// default gulp task
gulp.task('default', ['imagemin', 'htmlpage', 'scripts', 'styles', 'watch'], function() {
  return gutil.log('Gulp is running!')
});

Answer №1

To automatically refresh the browser when a file is modified, I recommend using browser-sync. Here's an example of how you can set it up:

const gulp = require('gulp');
const browserSync = require('browser-sync').create();

gulp.task('serve', function() {

    gulp.watch("app/**/*.js").on('change', browserSync.reload);
    gulp.watch("templates/**/*.html").on('change', browserSync.reload);
    gulp.watch("css/**/*.css").on('change', browserSync.reload);

    browserSync.init({
        server: "./"
    });

});

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Express and Node.js to display a page populated with information

On my webpage, I currently have a list of Teams displayed as clickable links. When a link for a specific Team is clicked, the Key associated with that Team is extracted and sent to the /team/:key route to retrieve the respective data. If the data retrieval ...

How can I link a Vue.js webpage with a WordPress site?

Looking to integrate a Vue.js 2 single page into an existing WordPress website? Perhaps you've already got an old WordPress site and now want to develop a new Vue tool or page that can be added seamlessly to the menu. How can this be achieved within W ...

Utilizing electron and Systemjs to import node modules

Is it feasible for systemjs to utilize require("remote").require("nodemodule") when the module cannot be located in its registry? A similar mechanism seems to be functioning when utilizing electron with typescript and commonjs modules... Has anyone succe ...

Sass new version causing error when importing local Google fonts

Currently, I am in the process of incorporating new Google fonts into various Sass files. These particular fonts are locally stored, and I'm including them using Sass along with URLs with the code snippet below: @font-face font-family: 'A ...

Tips for monitoring data changes and removing a class name from the DOM using the `$watch` method

In my particular case, I have a title that is currently active. When a user clicks on another subtitle, I switch the data between them. When a subtitle is clicked, I add a class name update. Once the update occurs, I want to monitor this in the active dir ...

Incorporating CSS Styles into an HTML Page

I'm encountering an issue where the CSS layout doesn't load when I try to view the document. Here's the content: <!DOCTYPE html> <html> <head> <body> <title>Waden B. Greaux Jr.</title> & ...

Currently, I am a beginner in the world of reactjs and I have embarked on a practice project to expand my knowledge of the platform. I am in need of assistance in creating a feature that

fetch("https://sampleapi.com/api/v1/employees").then( response => { response.json().then( result => { console.log(result.data); if (result.data.length > 0) { var content = ""; re ...

Is there a smarter approach in Vue.js to selectively add classes?

Within my Vue instance, I have implemented a method that conditionally generates HTML markup based on specific conditions. Although the markup remains the same for each scenario, only different styles are applied. I am curious if there is a more elegant a ...

Using the HTML <span> and svg elements together does not allow them to be inline with each other

In my current scenario, I have a fieldset that is inline with another one on the page. The specific fieldset in question contains an SVG circle and some text. My objective is to have both elements inline with each other, while allowing the fieldset to adj ...

Magical Stylist - Eradicate Indicators while Preserving Labeling

Recently, I've been experimenting with the Google styling wizard in an effort to remove markers while retaining labels for businesses. My objective is to eliminate the marker icons but still display the text labels such as "Jimmy Johns," "Boone Saloon ...

Utilizing Multiple UV maps in Three.js for Enhanced Object Texturing

I'm currently exploring how to apply two different textures on the front and back of a box. The issue I'm facing is that when I scale my box (using ExtrudeGeometry), the UV maps do not update as expected. As a result, I've resorted to defini ...

Problems with JQuery Ajax Json Response

Provided Form Section: <script type="text/javascript" src="js/aboneol.js"></script> <h4>Subscribe</h4> <div class="newsletter"> <span id="aboneolerror">< ...

Modifying a variable in $rootScope data will also update other instances of $rootScope data

Since I need to use the data in multiple controllers, I have stored it in $rootScope.currentCache. When the page loads, the data typically looks like this: { System: "Foo Bar", StartDateTime: "2014-11-27T12:35:00" } (please disregard any formatti ...

Remove bulleted list from HTML using JavaScript DOM

My task involved deleting the entire "agent" array using the removeChild() function, requiring the id of a <ul> element. However, I faced an issue as I couldn't set the id for the "ul" due to using the createElement() function. //old code < ...

Using automatic margins with tabs in the latest version of Bootstrap, known as Bootstrap

Currently exploring Bootstrap 5 and still getting the hang of it - so please bear with me if this question seems a bit rudimentary! I've been experimenting with tabs to create tabbed panes of local content. I've followed the code provided in the ...

Animating an image with CSS steps to create a captivating shaking

My attempt at creating a basic animation is not producing the desired smoothness. .animate { animation: motion 1.5s steps(27) forwards; } @keyframes motion { 100% { background-position: -5778px; } } <div class="animate ...

What is the correct way to utilize CodePen pens when incorporating HTML, CSS, and JavaScript into a template?

Is it best to place the beautifully designed elements from Codepen in separate files, or can the codes be directly pasted into custom files? I want to make sure that classes and properties aren't mixed with the main template's code. ...

Edit CSS attributes within Angular 2+ framework

When using jQuery, we have the ability to do the following: JQuery('.someStyle') .css({"background", "red"}) This allows us to directly change the CSS property in style. While working with Angular 2+, we can use [style.<property>] for ...

Retrieve cell characteristics based on row identification

The table below showcases various data attributes in its columns, along with jQuery code designed to create an object based on these attributes: <tbody> <tr id="1"> <td data-name1="Name 1">Name 1</td> ...

Next js is repeatedly calling a Firestore document in multiple instances during the fetching process

In my Next js 13 project, I am facing an issue while fetching a single document with an id from Firebase. Instead of returning just one read (which is expected since I'm fetching a single doc), it is returning multiple reads, sometimes ranging from 2 ...