A
A
Alexander2019-01-08 01:55:52
linux
Alexander, 2019-01-08 01:55:52

Double execution of a task in Gulp 4, what's the trouble?

When a task is executed, all rules are triggered, when files are changed, watch fixes everything, but sometimes tasks are performed twice. For example, if you change the SASS file after starting the default task, then it can be executed twice. What can be the problem?

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

gulp.task('styles', 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.reload({stream: true}))
});

gulp.task('scripts', function() {
  return gulp.src(source+'/js/**/*.js')
    .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(rename({prefix: '', suffix: '.min'}))
    .pipe(gulp.dest(source+'/js'))
    .pipe(browserSync.reload({stream: true}))
});

gulp.task('images', function() {
  return gulp.src(source+'/img/**/*')
    .pipe(cache(imagemin({
      interlaced: true,
      progressive: true,
      svgoPlugins: [{removeViewBox: false}],
      use: [pngquant()]
    })))
    .pipe(gulp.dest(source+'/img'))
});

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

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

gulp.task('default', gulp.series(
  gulp.series('styles', 'scripts', 'images'),
  gulp.parallel('watch', 'browser-sync')
));

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad Zhivotnev, 2016-04-04
@AlexeyMish

Because you need to write #!/bin/bash in the shabang, since it's bash, not pure sh.

S
Saboteur, 2016-04-04
@saboteur_kiev

Can you post the line from cron?
Your script works for me.
/usr/local/bin/smg1016_cfg_copier is the script itself?

A
Andrey Mikhalev, 2016-04-05
@Endru9

cd mnt

why permanent transition to mnt? especially the path is relative:
then it’s better like this:
file is in /mnt/ ? because the variable contains only its name, and the directory is always taken as the current one, if the absolute path to the file is not specified.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question