typescript 如何添加复制文件的后 tsc 构建任务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30191248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:00:10  来源:igfitidea点击:

How to add a post tsc build task that copy files?

typescriptvisual-studio-code

提问by MichaelS

How to add another task to VSCode, that copies files from x to y, after the tsc build task?

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

采纳答案by Brocco

You can use a task runner like gulp to accomplish this...

您可以使用像 gulp 这样的任务运行器来完成此任务...

You can configure vscode to run the buildtask below, which is dependent upon the compiletask.

可以配置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();
    }
  });
});

There is documentation about running gulp tasks via vscode here: https://code.visualstudio.com/Docs/tasks

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

回答by Iurii Perevertailo

You can use npm scriptsfor this. For example my package.json:

您可以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"
}

Here 2 scripts htmland viewsfor copying and task buildruns them concurrently. In tasks.jsonI have next:

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

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

So shift+cmd+Bwill run npm buildscript.

所以shift+cmd+B会运行npm build脚本。

回答by daleyjem

If you're running in some kind of "developer mode" and need to --watchfor file changes to run a task after every compile, I prefer using tsc-watchto accomplish this.

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

For example, in package.json:

例如,在package.json

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