aramgreat
@aramgreat
Я занимаюсь front-end разработкой

Почему падает производительность gulp спустя некоторое время?

Это мой gulpfile.js. Изначально все работает нормально. Например я что-то пишу в стилях (стайлусе) преобразование в css происходит за 350-400 миллисекунд потом с каждым преобразованием это время становится все больше и больше до 20 секунд может длится преобразование. Подскажите пожалуйста в чем проблема

'use strict'

const gulp            = require('gulp');
const stylus          = require('gulp-stylus');
const autoprefixer    = require('gulp-autoprefixer');
const uglifycss       = require('gulp-uglifycss');
const uglify          = require('gulp-uglifyjs');
const haml            = require('gulp-ruby-haml');
const include         = require("gulp-include");
const browserSync     = require('browser-sync').create();
const mainBowerFiles  = require('main-bower-files');
const del             = require('del');
const cached          = require('gulp-cached');
const path            = require('path');
const iconfont        = require('gulp-iconfont');
const iconfontCss     = require('gulp-iconfont-css');
const notify          = require('gulp-notify');
const plumber         = require('gulp-plumber');
const watch           = require('gulp-watch');


var plumberErrorHandler = {
    errorHandler: notify.onError({
        title: 'Gulp',
        message: 'Error: <%= error.message %>'
    })
}


gulp.task('stylus', function() {
    return gulp.src('app/stylus/{application,vendors}.styl')
        .pipe(plumber(plumberErrorHandler))
        .pipe(stylus({'include css': true}))
        .pipe(autoprefixer(['last 15 version', '> 1%']))
        //.pipe(uglifycss())
        .pipe(gulp.dest('build/css'));
});


var fontName = 'quest-icons';
gulp.task('icons', function(){
    return gulp.src(['app/icons/*.svg'])
        .pipe(iconfontCss({
            fontPath: '../fonts/',
            fontName: fontName,
            path: 'app/icons/icons.css',
            targetPath: '../stylus/vendors/icons.css',
            cssClass: "quest",
           
            
        }))
        .pipe(iconfont({
            fontName: fontName,
            formats: ['eot', 'svg', 'ttf', 'woff', "woff2"],
            normalize:true
        }))
        .pipe(gulp.dest('app/fonts'));
});

gulp.task('server', function(){
    browserSync.init({
        server: 'build',
        online: true
    });
    browserSync.watch('build/**/*.*').on('change', browserSync.reload)
});

// get Bower files
gulp.task('bowerFiles', function() {
    return gulp.src(mainBowerFiles())
        .pipe(gulp.dest(function(file){
            return file.extname == '.js' ? 'app/js/vendors' :
                file.extname == '.css' ? 'app/sass/vendors' : 'build/fonts';
        }));
});
 
gulp.task('haml', function() {
    return gulp.src('app/*.haml')
        .pipe(plumber(plumberErrorHandler))
        .pipe(include())
        //.on('error', console.log)
        .pipe(cached('haml'))
        .pipe(haml({doubleQuote: true}).on('error', function(e) { console.log(e.message); }))
        .pipe(gulp.dest('./build'));
});
gulp.task('js', function() {
    return gulp.src('app/js/{application,vendors}.js')
        .pipe(include()).on('error', console.log)
        .pipe(cached('js'))
        //.pipe(uglify())
        .pipe(gulp.dest('build/js'));  
});

gulp.task('images', function() {
    return gulp.src('app/img/**/*.*')
        .pipe(gulp.dest('build/img'));
});
gulp.task('fonts', function() {
    return gulp.src('app/fonts/**/*.*')
        .pipe(cached('fonts'))
        .pipe(gulp.dest('build/fonts'));
});
gulp.task('appFiles',  gulp.series('images', 'fonts', 'icons', 'js'));

gulp.task('clean', function(){
    return del('build')
});

gulp.task('build', gulp.series('clean', 'bowerFiles', "appFiles", 'stylus', 'haml'));



gulp.task('watch', function(){
    gulp.watch('app/stylus/**/*', gulp.series('stylus'));
    gulp.watch('app/**/*.haml', gulp.series('haml')).on('unlink', function(filepath){
        delete cached.caches.haml[path.resolve(filepath)]
    });
    gulp.watch('app/icons/**/*', gulp.series('icons'));
    gulp.watch('app/js/**/*', gulp.series('js'));
    gulp.watch('app/fonts/**/*', gulp.series('fonts')).on('unlink', function(filepath){
        delete cached.caches.haml[path.resolve(filepath)]
    });
    gulp.watch('app/img/**/*', gulp.series('images'));
    
});

gulp.task('default',  gulp.series('build',  gulp.parallel('watch', 'server')));
  • Вопрос задан
  • 472 просмотра
Пригласить эксперта
Ответы на вопрос 3
nicothin
@nicothin
веб-разработчик с 2000 г.
У меня та же проблема с LESS, плюс знаю о той же проблеме с Sass.
В моем случае, это наблюдается на Win10 c gulp 4 (на OSX не наблюдается).
https://github.com/nicothin/test_area_LESS--gulp/t... — репозиторий, созданный для эмуляции проблемы.
Ответ написан
style_nes
@style_nes
Фронтенд разработчик
Попробуйте сохранять изменения в файлах в другом редакторе.
Ответ написан
Комментировать
@mrG0bliN
Потому что нужно использовать { since: gulp.lastRun('__nameTask') }
без этого с каждой новой картинкой вы будете таскать их туда сюда
залейте еще 500 картинок каждой по 1 мб, у вас билд будет собиратся пол часа
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы