How to use “compileOnSave” in VS Code?

青春壹個敷衍的年華 提交于 2021-02-08 05:44:54

问题


Typescript has a configuration option for auto compilation of typescript, as documented here.

{
   "compileOnSave": true,
   "compilerOptions": {
       "noImplicitAny" : true
   }
}

But simply including this in my tsconfig.json file is not enough to trigger auto compilation. I use MS Visual Studio Code as my IDE. How do I trigger the "compile on save" behavior?


回答1:


According to the TypeScript site:

"This feature is currently supported in Visual Studio 2015 with TypeScript 1.8.4 and above, and atom-typescript plugin."

So, it isn't supported by Visual Studio Code at this time. I use this option at work with Visual Studio 2015 and at home with Atom and it works fine. This is actually one of the reasons I switched from Visual Studio Code to Atom.




回答2:


Try watch parameter at compilerOptions... It will be monitoring changes in your ts files and be automatically refresh in your js files. Example:

    "compilerOptions": {
        "module":"commonjs",
        "noImplicitAny": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "outDir": "Scripts/javascript",
        "watch": true,
        "sourceMap": true       
    }



回答3:


I had the same issue on my Atom IDE version - 1.34.0 running on windows 10 x64 system.

The issue was fixed after installing missing packages atom-ide-ui and atom-typescript.

Here is how my tsconfig.json file looks like.

{

  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./build",
    "rootDir": "./src",
    "noImplicitAny": true
  },
  "compileOnSave": true
}

I have TypeScript version 3.2.4 installed globally.



来源:https://stackoverflow.com/questions/36428368/how-to-use-compileonsave-in-vs-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!