The last post I've found about this topic is from autumn 2015. I think this is one of those basic things every developer will need sooner or later.
I would like to differentiate my gulp tasks based on actual build configuration (debug/staging/release) etc. I don't actually need to connect it with Visual Studio's solution configuration.
Here is a proposed solution: we would have this as an option inside Task Runner Explorer, and then at task binding I could tick in in which configurations I would like to run the task.
Is it only me who would need this?
答案 0 :(得分:0)
我不使用TRX,但你可以将任何这些任务绑定到像#34; Project Open"或者"在构建之前。"我在父任务中使用gulp-if和set变量,然后使用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);
}
};