A
A
Alexander2019-01-04 23:14:33
JavaScript
Alexander, 2019-01-04 23:14:33

The task in gulpfile.js doesn't work, what's wrong?

When writing in the gulp terminal, the task for watch and browser-sync works, but the rules for sass do not work. What could be the problem?

/////// HTML TASK /////////////////////////////////////////////////////////////

gulp.task('code', function() {
  return gulp.src(''+source+'/*.html')
    .pipe(browserSync.reload({ stream: true }))
});

/////// SASS TASK /////////////////////////////////////////////////////////////

gulp.task('style', function(){
  return gulp.src(''+source+'/'+syntax+'/**/*.'+syntax+'')
    .pipe(sass({ outputStyle: 'expanded' }).on("error", notify.onError()))
    .pipe(autoprefixer(['last 15 versions']))
    .pipe(cleancss({ level: { 1: { specialComments: 'all' } } }))
    .pipe(rename({ prefix: '', suffix: '.min' }))
    .pipe(gulp.dest(''+source+'/css'))
    .pipe(browserSync.stream())
});

/////// SCRIPTS TASK ///////////////////////////////////////////////////////////

gulp.task('scripts', function() {
  return gulp.src([
    ''+source+'/libs/jquery/dist/jquery.min.js',
    ''+source+'/js/common.js',
  ])
    .pipe(concat('scripts.min.js'))
    .pipe(uglify()) // Mifify js
    .pipe(rename({prefix: '', suffix: '.min'}))
    .pipe(gulp.dest(''+source+'/js'))
    .pipe(browserSync.reload({ stream: true }))
});

/////// BROWSER-SYNC TASK //////////////////////////////////////////////////////

gulp.task('browser-sync', function() {
  browserSync({
    server: {
      baseDir: ''+source+''
    },
    notify: false,
  })
});

/////// WATCH TASK /////////////////////////////////////////////////////////////

gulp.task('watch', function() {
  gulp.watch(''+source+'/*.html', gulp.parallel('code'));
  gulp.watch(''+source+'/'+syntax+'/**/*.'+syntax+'', gulp.parallel('style'));
  gulp.watch(['libs/**/*.js', ''+source+'/js/common.js'], gulp.parallel('scripts'));
});

gulp.task('default', gulp.parallel('watch', 'browser-sync'));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NiyazNA, 2019-01-04
@NiyazNA

Perhaps you have version 4 of gulp. And now a lot has changed. I advise you to check what version you have.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question