S
S
sylens2020-09-02 14:52:55
gulp.js
sylens, 2020-09-02 14:52:55

gulp4. How to solve the task looping problem?

The scripts task loops, everything works as it should, but the text in the terminal constantly runs down.
How to solve the problem?

Terminal:

...
[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'));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question