繁体   English   中英

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

[英]VS Code: watch typescript on save file

在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选项是真的。 好吧,看起来这还不足以将.ts文件编译为.js,就像atom-typescript一样。 基本上,在保存.ts时,新编译的.js应该位于.ts文件的同一目录中。

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

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

{
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-w", "-p", "."],
    "showOutput": "silent",
    "isWatching": true,
    "problemMatcher": "$tsc-watch"
}

不需要tsconfig.jsonwatch选项。

你必须在.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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM