在 VS Code 中构建之前运行 Gulp 任务

问题描述

我有一个新的空 .NET Core 项目。我可以在 VS Code 中构建之前自动运行 Gulp 任务吗?

我可以通过执行 styles 手动运行 VS Code package manager -> Tasks: Run Task -> gulp -> gulp: styles 任务,但是当我构建它时它不会运行。

/// <binding beforebuild="styles"></binding>

var gulp = require('gulp');
var gulpless = require('gulp-less');

gulp.task('styles',function () {
    var srcfile = 'styles/Styles.less';
    var dest = 'wwwroot';
    return gulp
        .src(srcfile)
        .pipe(gulpless())
        .pipe(gulp.dest(dest));
});

我从一些在线教程中得到了这段代码,除了第一行之外,一切正常。

这应该在 VS Code 中工作还是只是 Visual Studio 的奢侈品?

解决方法

//In this case we’re adding the a task before other task.

gulp.task('watch',['array','of','tasks','to','complete','before','watch'],function (){
  // ...
})


//And in this case we’re adding for example the browserSync task.

gulp.task('watch',['browserSync'],function (){
  gulp.watch('app/scss/**/*.scss',['sass']); 
  // Other watchers
})


//We’ll also want to make sure sass runs before watch so the CSS will already be the latest whenever we run a Gulp command.

gulp.task('watch',['browserSync','sass'],['sass']); 
  // Other watchers
});

阅读本文档:Gulp for Beginners