我不使用TRX,但可以將這些任務中的任何一個綁定到「項目打開」或「構建之前」之類的事件。我使用gulp-if並在我的父任務中設置變量,然後使用run-sequence
調用所有子任務。 (未測試的代碼)
gulpfile.js
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
requireDir = require('require-dir')('./js/gulp/tasks'),
runSequence = require('run-sequence'),
vars = require('./variables');
gulp.task('dev', function(){
vars.isProduction = false;
runSequence('clean', ['css', 'scripts']);
});
gulp.task('prod', function(){
vars.isProduction = true;
runSequence('clean', ['css', 'scripts']);
});
/js/gulp/tasks/scripts.js
gulp.task('scripts', function() {
return gulp.src('scripts/**/*.js')
.pipe($.concat('app.min.js'))
.pipe($.if(vars.isProduction, $.uglify()))
.pipe(gulp.dest('/js'))
.pipe($.plumber({
errorHandler: vars.onError
}))
.pipe($.if(!vars.isProduction, $.livereload()));
variables.js
module.exports = {
isProduction: false,
onError: function (err) {
log(err);
}
};
謝謝你 你的答案。我還不知道如何在TRX AfterBuild中分別綁定'dev'和'prod'任務(例如)。你仍然需要一些關於使用哪一個的設置,或者我誤解了某些東西。 –
我可能誤解了你的OP不需要綁定到Visual Studio的解決方案配置。但是我的開發任務通常只是吞噬觀察者,我在[單獨的命令窗口](https://visualstudiogallery.msdn.microsoft.com/4e84e2cf-2d6b-472a-b1e2-b84932511379)中運行這些任務。如果您使用構建服務器,則可以將構建任務作爲構建定義的一部分運行 – Barryman9000