VS代码:在保存文件上观看打字稿

时间:2016-01-05 20:39:42

标签: typescript task visual-studio-code tsc tsd

在Visual Studio代码中,我在tsconfig.json

中的代码中有以下代码
{
    "version": "1.6.0",
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "experimentalAsyncFunctions": true,
        "isolatedModules": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false,
        "preserveConstEnums": true,
        "suppressImplicitAnyIndexErrors": true
    },
    ...
}

如您所见,watch选项为true。好吧,看起来这还不足以将.ts文件编译为.js,就像atom-typescript一样。基本上,在保存.ts时,新编译的.js应该位于.ts文件的同一目录中。

另外,我想避免在我的根项目中使用gulp,因为我已经使用gulpfile.coffee作为其他方法。有人有线索吗?

2 个答案:

答案 0 :(得分:2)

使用最新版本的VS Code 1.7.2和Typescript 2.0.10,您只需要在.vscode/tasks.json

中包含以下代码
{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-w", "-p", "."],
    "showOutput": "silent",
    "isWatching": true,
    "problemMatcher": "$tsc-watch"
}

不需要watch中的tsconfig.json选项。

答案 1 :(得分:1)

你必须在.vscode文件夹中定义tasks.json,如下所示:

{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "showOutput": "silent",
    "args": ["HelloWorld.ts"],
    "problemMatcher": "$tsc"
}

您可以在此处找到有关它的更多信息:https://code.visualstudio.com/Docs/languages/typescript

相关问题