簡體   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