Search code examples
typescriptvisual-studio-codegulpminifyvscode-tasks

VSCode, running multiple Gulp tasks


Evening, i've got an issue with running multiple Gulp tasks in VSCode, whereby only the first task is ever run, and the second is just ignored. Both tasks work individually when I 'Ctrl-Shift-B', but together, nada.

Two really simple commands, one that builds my Typescript into JS, the other to just minify and concatenate. Just regular stuff.

Here's my gulpfile.js

var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ts = require('gulp-typescript');

//  Task that is used to compile the Typescript in JS 
gulp.task('typescriptCompilation', function () {
  return gulp.src('scripts/*.ts')
    .pipe(ts({
        noImplicitAny: true,
        out: 'output.js'
    }))
    .pipe(gulp.dest('scripts')); 
});

//  Task that is used to minify anf concatanate the JS into one file for distribution
gulp.task('minifyAndConcat', function() {
  return gulp.src('scripts/*.js') // read all of the files that are in script/lib with a .js extension
    .pipe(concat('all.min.js')) // run uglify (for minification) on 'all.min.js'
    .pipe(uglify({mangle: false})) // run uglify (for minification) on 'all.min.js'
    .pipe(gulp.dest('dist/js')); // write all.min.js to the dist/js file
});

And the tasks.json

{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [],
"tasks": [
    {
        "taskName": "typescriptCompilation",
        "isBuildCommand": true,
        "showOutput": "always"
    },
    {
        "taskName": "minifyAndConcat",
        "isBuildCommand": true,
        "showOutput": "always"
    }
]
}

It's most likely something simple i've missed, but i'm new to Gulp and I can't see it.....


Solution

  • Why don't you try to create one more gulp task :

    gulp.task('default', ['typescriptCompilation', 'minifyAndConcat']);
    

    And then in your tasks.json :

    {
    "version": "0.1.0",
    "command": "gulp",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "default",
            "isBuildCommand": true,
            "showOutput": "always"
        }
      ]
    }