【问题标题】:Run Gulp task before build in VS Code在构建 VS Code 之前运行 Gulp 任务
【发布时间】:2021-06-11 15:25:36
【问题描述】:

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

我可以通过 VS Code package manager -> Tasks: Run Task -> gulp -> gulp: styles 手动运行 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 的奢侈品?

【问题讨论】:

  • 您可以创建一个复合任务,由一系列已定义的多个任务组成
  • 好吧,这似乎是个好主意。但是上面的代码在 VS Code 中不能用吗?
  • dotnet build,你的意思是控制台命令吗? VSCode 无法控制终端
  • 但是 gulpfile 是在项目中,所以我想也许 .NET 可以识别它并在构建过程之前运行任务?不对吗?

标签: asp.net-core visual-studio-code gulp less


【解决方案1】:

//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'], function (){
  gulp.watch('app/scss/**/*.scss', ['sass']); 
  // Other watchers
});

阅读此文档:Gulp for Beginners

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-03
    • 2011-12-30
    相关资源
    最近更新 更多