Browsersync detects changes in css but it does not inject the new css since 2.24.0 version. You have to manually refresh the page to see the changes
Just use example on https://browsersync.io/docs/gulp to reproduce this issue.
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./app"
});
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']);
-
gulp.task('sass', () => {
gulp
.src('src/scss/main.scss')
.pipe(ifElse(isDev, () => sourcemaps.init()))
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(ifElse(isDev, () => sourcemaps.write()))
.pipe(ifElse(!isDev, () => cleanCSS()))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
Hope to fix it soon.
I've got the same issue and am unable to fix it. I've tried:
Browser reloading does work for other things like html changes, but browser syncing (css injection) doesn't. For what i can tell this happens:
When i inspect websockets in my chrome browser (dev tools > network > ws) i see this data in the send frame:
42/browser-sync,["file:reload",{"ext":"css","path":"C:\\#server\\test\\gulp-test\\css\\style.css","basename":"style.css","event":"change","type":"inject","log":false}]
This tells me the data is actually send, but nothing happens afterwards. My guess is that browser-sync-client.js?v=2.24.2 fails in inserting this stylsheet and fails silently.
Use example on https://browsersync.io/docs/gulp to reproduce this issue. (same as above from @Chmylov)
-
`var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var reload = browserSync.reload;
var src = {
scss: 'sass/.scss',
css: 'css',
html: '.html'
};
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./"
});
gulp.watch(src.scss, ['sass']);
gulp.watch(src.html).on('change', reload);
});
gulp.task('sass', function() {
return gulp.src(src.scss)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(src.css))
.pipe(reload({stream: true}));
});
gulp.task('default', ['serve']);`
For everyone who can't wait, workaround. Use http://livereload.com/ and https://www.npmjs.com/package/gulp-livereload . This works lighting fast!
We can simply use the old version to instead.
npm uninstall browser-sync
npm install [email protected]
I'll be looking at this today
fixed in [email protected]
Most helpful comment
We can simply use the old version to instead.
npm uninstall browser-syncnpm install [email protected]