S
S
shynga2020-01-31 07:44:18
JavaScript
shynga, 2020-01-31 07:44:18

CSS files not updating in BrowserSync?

Good afternoon!
There is code in gulpfile.js but it doesn't work

let gulp        = require('gulp'),
    minCSS      = require('gulp-clean-css'),
    browserSync = require('browser-sync').create();

// Static Server + watching css/html files
gulp.task('serve', gulp.series ('minCSS'), async function() {

    browserSync.init({
        server: 'app/'
    });

    gulp.watch('app/styles/*.css', gulp.series ('minCSS'));
    gulp.watch('app/*.html').on('change', browserSync.reload);
});

// Minify CSS files
gulp.task('minCSS', async function () {
    gulp.src('app/styles/*.css')
        .pipe(minCSS())
        .pipe(gulp.dest('temp/css'))
        .pipe(browserSync.stream());
});

gulp.task('default', gulp.series ('serve'));


When typing gulp on the command line, this comes out:
assert.js:374
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task never defined: minCSS
    at getFunction (C:\Users\User\Desktop\trillions\node_modules\undertaker\lib\helpers\normalizeArgs.js:15:5)
    at map (C:\Users\User\Desktop\trillions\node_modules\arr-map\index.js:20:14)
    at normalizeArgs (C:\Users\User\Desktop\trillions\node_modules\undertaker\lib\helpers\normalizeArgs.js:22:10)
    at Gulp.series (C:\Users\User\Desktop\trillions\node_modules\undertaker\lib\series.js:13:14)
    at Object.<anonymous> (C:\Users\User\Desktop\trillions\gulpfile.js:6:25)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-01-31
@shynga

Hello. First, run the command gulp --tasks in the console to make sure that such a task is registered in gulp. Second, better use gulp 4 syntax. Example:

function cssMin(cb) {
  cb();

  return gulp.src(`${config.css}/*.css`)
    .pipe(gulpif(
      config.env === 'production',
      cleanCSS({
        level: 2,
      }))
    )
    .pipe(gulp.dest(`${config.css}/`));
}

exports.cssMin = cssMin;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question