如何添加复制文件的post tsc build任务?

时间:2015-05-12 12:42:53

标签: typescript visual-studio-code

如何在VSCode上添加另一个任务,在tsc构建任务之后将文件从x复制到y?

3 个答案:

答案 0 :(得分:9)

您可以使用npm scripts。例如我的package.json

"scripts": {
  "compile": "tsc -p . ",
  "html": "cp -r ./src/public/ ./bin/public/",
  "views": "cp -r ./src/views/ ./bin/views/",
  "build": "npm run compile && npm run views && npm run html"
}

这里有两个用于复制的脚本htmlviews以及任务build同时运行它们。 在tasks.json我有下一个:

{
    "version": "0.1.0",
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "silent",
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "run",
                "build"
            ]
        }
    ]
}

因此shift+cmd+B将运行npm build脚本。

答案 1 :(得分:6)

你可以使用像gulp这样的任务运行来完成这个......

您可以配置vscode以运行下面的build任务,这取决于compile任务。

var gulp = require('gulp'),
  exec = require('child_process').exec;

gulp.task('build', ['compile'], function () {
  return gulp.src('./config/**/*.json')
    .pipe(gulp.dest('./dist'));
});

gulp.task('compile', function (done) {
  exec('tsc -p ./app', function (err, stdOut, stdErr) {
    console.log(stdOut);
    if (err){
      done(err);
    } else {
      done();
    }
  });
});

有关于通过vscode运行gulp任务的文档:https://code.visualstudio.com/Docs/tasks

答案 2 :(得分:0)

如果您以某种“开发人员模式”运行,并且需要--watch进行文件更改以在每次编译后运行任务,我更喜欢使用tsc-watch来完成此任务。

例如,在package.json中:

{
  "scripts": {
    "dev": "tsc-watch --onSuccess=\"yarn otherThing\"",
    "otherThing": "echo \"hi\""
  }
}
相关问题