@sylens

Gulp4. Как решить проблему зацикливания таска?

Зацикливается таск scripts, все работает как надо, но текст в терминале постоянно бежит вниз.
Как решить проблему?

Терминал:
...
[14:48:32] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:32] Finished 'myScripts' after 22 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:32] Finished 'scripts' after 23 ms
[14:48:32] Starting 'myScripts'...
[14:48:32] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:32] Finished 'myScripts' after 20 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:32] Finished 'scripts' after 22 ms
[14:48:32] Starting 'myScripts'...
[14:48:32] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:32] Finished 'myScripts' after 30 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:32] Finished 'scripts' after 31 ms
[14:48:33] Starting 'myScripts'...
[14:48:33] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:33] Finished 'myScripts' after 30 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:33] Finished 'scripts' after 28 ms
[14:48:33] Starting 'myScripts'...
[14:48:33] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:33] Finished 'myScripts' after 21 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:33] Finished 'scripts' after 21 ms
[14:48:33] Starting 'myScripts'...
[14:48:33] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:33] Finished 'myScripts' after 22 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:33] Finished 'scripts' after 23 ms
[14:48:33] Starting 'myScripts'...
[14:48:33] Starting 'scripts'...
[Browsersync] 6 files changed (Controller.js, Model.js, View.js, adjustment.js, js.min.js, main.js)
[14:48:33] Finished 'myScripts' after 24 ms
[Browsersync] 1 file changed (js.min.js)
[14:48:33] Finished 'scripts' after 26 ms
...


gulpfile.js:
var gulp = require('gulp'),
    sass = require('gulp-sass'),
    browserSync = require('browser-sync'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglifyjs'),
    cssnano = require('gulp-cssnano'),
    rename = require('gulp-rename'),
    clear = require('del'),
    autoprefixer = require('gulp-autoprefixer'),
    sourceMaps = require('gulp-sourcemaps'),
    stripCssComments = require('gulp-strip-css-comments'),
    spritesmith = require('gulp.spritesmith');

gulp.task('sass', function () {
    return gulp.src('app/scss/**/*.scss')
        .pipe(sourceMaps.init())
        .pipe(sass())
        .pipe(autoprefixer(['last 15 versions']))
        .pipe(cssnano())
        .pipe(sourceMaps.write())
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest('app/css'))
        .pipe(browserSync.reload({stream: true}))
});


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

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

gulp.task('myScripts', function () {
    return gulp.src('app/js/**/*.js')
        .pipe(browserSync.reload({stream: true}))
});

gulp.task('scripts', function () {
    return gulp.src([
        'app/importJS/**/*.js'
    ])
        .pipe(concat('js.min.js'))
        //.pipe(uglify())
        .pipe(gulp.dest('app/js'))
        .pipe(browserSync.reload({stream: true}))
});

gulp.task('spritesmith', async function () {
    var spriteData = gulp.src('app/sprites/**/*')
        .pipe(spritesmith({
            imgName: 'sprite.png',
            cssName: '_sprite.css' //необходимо отредактировать пути к спрайтам
        }));
    spriteData.img.pipe(gulp.dest('app/img/'));
    spriteData.css.pipe(gulp.dest('app/sass/import/'));
});

gulp.task('clean', async function () {
    return clear.sync('dist')
});

gulp.task('build', async function () {
    gulp.src('app/css/main.min.css')
        .pipe(stripCssComments())
        .pipe(gulp.dest('dist/css'));

    gulp.src('app/fonts/**/*')
        .pipe(gulp.dest('dist/fonts'));

    gulp.src('app/js/**/*')
        .pipe(gulp.dest('dist/js'));

    gulp.src('app/*.html')
        .pipe(gulp.dest('dist'));

    gulp.src('app/img/**/*')
        .pipe(gulp.dest('dist'));
});

gulp.task('watch', function () {
    gulp.watch('app/scss/**/*.scss', gulp.parallel('sass'));
    gulp.watch('app/*.html', gulp.parallel('code'));
    gulp.watch('app/js/**/*.js', gulp.parallel('myScripts'));
    gulp.watch('app/js/**/*.js', gulp.parallel('scripts'));
});

gulp.task('rebuild', gulp.series('clean', 'build'));

gulp.task('default', gulp.parallel('sass', 'scripts', 'browser-sync', 'watch'));
  • Вопрос задан
  • 100 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы