首页 > 解决方案 > 我的代码在 gulp 任务结束后执行

问题描述

我构建了一个异步 gulp 任务来将一些 sass 文件转换为 css 文件,但我在执行时间线代码时遇到了一些麻烦。我需要在循环中执行这个任务,代码在 gulp 任务结束后执行

  async build() {
        var self = this;
        var tasks = await this.themes.map(async(theme) => {

            return gulp.src(this.templatesPath + '/' + this.pattern)
            .pipe(header('@import \'' + this.themesPath + '/' + theme + '/' + this.themeFile + '\';'))
            .pipe(sass.sync().on('error', gutil.log))
            .pipe(rename(function (path: any) {
                var file = path.basename + path.extname;
                path.dirname += '/' + file;

                gutil.log(self.folders[theme][file]);
            }))
            .pipe(gulp.dest(this.themesPath + '/' + theme))

            gutil.log('loop');

        });

        gutil.log('end');
    }

重命名函数中的gutil.log 输出总是在任务结束后输出

[18:08:34] 开始“构建”...
[18:08:34] 结束
[18:08:34] 33 毫秒后完成“构建”
[18:08:34] [ { '$': { 'jcr:primaryType': 'jnt:file' },
'jcr:content': [[Object] ] } ]
[18:08:34] [ { '$': { 'jcr:primaryType': 'jnt:file ' },
'jcr:content': [ [对象] ] } ]

当我执行其他任务时,如何处理循环结束以确保我的对象被填充?

标签: gulp

解决方案


推荐阅读