0

I used this gulp file until recently. Now everything still works, the CSS still gets compiled except injecting the compiled CSS back into the browser.

Thanks for your time!

var gulp = require('gulp');
var gutil = require('gulp-util');
var bs = require('browser-sync').create();

// Include plugins
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var less = require('gulp-less');
var minifycss = require('gulp-clean-css');
var streamqueue = require('streamqueue');

gulp.task('bs', function () {
   var files = [
      'libraries/file1.css',
   ];

   bs.init(files, {       
      proxy: 'localhost',
      port: '80',
      baseDir: './',
      startPath: 'joomla'
   })

   gulp.watch("libraries/file1.css", ['fcss']);

});

gulp.task('fcss', function() {
    var themes = ['.theme1','.theme2', '.theme3'];

    themes.forEach( function(theme) {
      return gulp.src(['libraries/'+theme+'.css', 
        'libraries/file1.css'
      ])
      .pipe(concat('style'+theme+'.css'))
      .pipe(gulp.dest('media/css'))
      .pipe(rename({suffix: '.min'}))
      .pipe(minifycss({advanced:false, keepSpecialComments : 0}))
      .pipe(gulp.dest('media/css'))

      .pipe(bs.stream());
   });
});

1 Answer 1

2

Try running browsersync before you minify css:

gulp.task('fcss', function() {
    var themes = ['.theme1','.theme2', '.theme3'];

    themes.forEach( function(theme) {
      return gulp.src(['libraries/'+theme+'.css', 
        'libraries/file1.css'
      ])
      .pipe(concat('style'+theme+'.css'))
      .pipe(bs.stream())
      .pipe(gulp.dest('media/css'))
      .pipe(rename({suffix: '.min'}))
      .pipe(minifycss({advanced:false, keepSpecialComments : 0}))
      .pipe(gulp.dest('media/css'));
   });
});
Sign up to request clarification or add additional context in comments.

1 Comment

In a way, yes, timing. The way gulp streams work, means that each pipe is run sequentially. To work correctly, browser sync needs to receive a stream of uncompressed css (before minification).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.