简体   繁体   English

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

[英]VS Code: watch typescript on save file

In Visual Studio Code, I have the following code in code in tsconfig.json 在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
    },
    ...
}

As you can see, the watch option is at true. 如您所见, watch选项是真的。 Well, look like this isn't enough to compile a .ts file to .js just like the atom-typescript does. 好吧,看起来这还不足以将.ts文件编译为.js,就像atom-typescript一样。 Basically, the new compiled .js should be in the same directory of the .ts file when saving the .ts. 基本上,在保存.ts时,新编译的.js应该位于.ts文件的同一目录中。

Also, I'd like avoid using gulp in my root project, since I already use a gulpfile.coffee for other means. 另外,我想避免在我的根项目中使用gulp,因为我已经将gulpfile.coffee用于其他方法。 Anyone has a clue? 有人有线索吗?

With the most recent versions of VS Code 1.7.2 and Typescript 2.0.10 you just need to have the following code in .vscode/tasks.json 使用最新版本的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"
}

The watch option in tsconfig.json is not needed. 不需要tsconfig.jsonwatch选项。

you have to define a tasks.json in the .vscode folder looking something like this: 你必须在.vscode文件夹中定义tasks.json,如下所示:

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

you can find more information about it here: https://code.visualstudio.com/Docs/languages/typescript 你可以在这里找到更多相关信息: https//code.visualstudio.com/Docs/languages/typescript

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

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