【问题标题】:VSCode, running multiple Gulp tasksVSCode,运行多个 Gulp 任务
【发布时间】:2015-12-26 19:20:12
【问题描述】:

晚上,我在 VSCode 中运行多个 Gulp 任务时遇到了问题,即只有第一个任务运行,第二个任务被忽略。当我“Ctrl-Shift-B”时,这两个任务单独工作,但一起工作,nada。

两个非常简单的命令,一个将我的 Typescript 构建到 JS 中,另一个只是缩小和连接。只是普通的东西。

这是我的 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
});

还有 tasks.json

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

这很可能是我错过了一些简单的东西,但我是 Gulp 的新手,我看不到它.....

【问题讨论】:

  • 可能是因为它并行运行任务..你可以尝试使用运行序列。问题解决了吗?
  • 为什么不创建一个同时运行两者的新任务呢?或者甚至添加从“typescriptCompilation”到“minifyAndConcat”的依赖项。我不确定 vscode 是运行多个任务还是只运行第一个。

标签: typescript visual-studio-code gulp minify vscode-tasks


【解决方案1】:

你为什么不尝试再创建一个 gulp 任务:

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

然后在你的 tasks.json 中:

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

【讨论】:

  • 这就是我最后所做的,我现在将 tasks.json 留给 typescript 编译。我会将此标记为答案。无论如何干杯!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-12
  • 1970-01-01
  • 2017-09-04
  • 2016-04-14
  • 1970-01-01
  • 1970-01-01
  • 2017-03-13
相关资源
最近更新 更多