使用gulp手表获得可能的泄漏,任务每次需要更长的时间 [英] Getting a possible leak using gulp watch, tasks take longer each time

查看:122
本文介绍了使用gulp手表获得可能的泄漏,任务每次需要更长的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gulp在ASP.NET5网站中编译和缩小我的SASS以用作CDN。我写了一个监视器,监视我的* .scss文件,然后使用依赖关系编译scss,然后concat / minify它一个style.min.css。

I'm using gulp to compile and minify my SASS in an ASP.NET5 website to use as a CDN. I've written a watcher that watches my *.scss files, it then uses dependencies to compile the scss and then concat/minify it into one style.min.css.

我遇到的问题是,项目打开的时间越长,或者至少对于gulp任务的每个顺序运行,它们会显着延长到我只有大约20分钟的时间,并且编译任务正在服用15+秒,缩小正在采取25 +秒。

The issue I'm having is that the longer the project is open, or at least with each sequential run of the gulp tasks, they get considerably longer to the point where I had only been developing for about 20 minutes, and the compile task was taking 15+ second, and the minify was taking 25+ seconds. The very first run of each takes about 1 or 2 milliseconds so I'm really lost as to what's going on.

这是我的观察者:

gulp.task('Watch:Sass', function () {
    watch(paths.cdn.sassLoc, { verbose: true }, function () {
        gulp.start("Min:css"); 
    });
});

这是 Min:css

gulp.task("Min:css", ["Compile:Sass"], function () {
    return gulp.src([paths.cdn.cssLoc, "!" + paths.cdnMinCssLoc + "**/*.*"])
        .pipe(concat(paths.cdn.cssDest))
        .pipe(cssmin())
        .pipe(plumber({
            handleError: function (err) {
                console.log(err);
                this.emit('end');
            }
        }))
        .pipe(gulp.dest("."));
});

这里是 Compile:Sass 正在注册为依赖项:

And here is the Compile:Sass task that is being injected as a dependency:

gulp.task('Compile:Sass', function () {
    gulp.src(paths.cdn.imagesLoc)
        .pipe(gulp.dest(paths.webroot + '/css/min/images'));
    return gulp.src(paths.cdn.sassLoc).pipe(plumber({
        handleError: function (err) {
            console.log(err);
            this.emit('end');
        }
    }))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest(paths.cdn.sassDest));
});

这是否因为我使用了退货?

Could it be because of my use of returns?

任何帮助将非常感谢,因为我必须重新启动Visual Studio每半个小时左右,这是非常令人沮丧的!

Any help would be greatly appreciated as I have to restart Visual Studio every half hour or so which gets extremely frustrating!

我确定我已经包括

推荐答案

在这种情况下,它实际上是我的return语句

In this case it was in fact my return statements that were in the wrong place.

为了解决这个问题,我不得不在 gulp.src(...) 并且我必须在 Compile:Sass gulp的末尾添加 return true 任务。我还完成了 Min:Css 任务的返回,现在我的编译任务需要〜1.5ms,我的任务需要〜600us。

In order to fix the issue, I had to take off the return on the gulp.src(...) and I had to add a return true to the end of the Compile:Sass gulp task. I also took the return off of the Min:Css task completely and now my compile task takes ~1.5ms and my min task takes ~600us.

这是最后的 Compile:Sass 任务:

gulp.task('Compile:Sass', function () {
    gulp.src(paths.cdn.imagesLoc)
        .pipe(gulp.dest(paths.webroot + '/css/min/images'));
    gulp.src(paths.cdn.sassLoc).pipe(plumber({
        handleError: function (err) {
            console.log(err);
            this.emit('end');
        }
    }))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest(paths.cdn.sassDest));

    return true;
});

这篇关于使用gulp手表获得可能的泄漏,任务每次需要更长的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆