2016-09-26 54 views
6

当我保存时,我无法让visual studio将typescript编译为js。当tsconfig.json在项目中时,保存时的Typescript编译不工作

enter image description here

我有一个xproj(净框架asp.net核心) 打字稿2.0.3工具为Visual Studio 2015年更新3

我试图启用tsconfig.json "watch" : true但它表示当前主机不受支持。

我去工具>选项>文本编辑器>打字稿>项目并启用了“自动编译打字稿文件不属于项目的一部分”

enter image description here

尽管如此,.ts文件的变化将体现在.js文件中仅在编译期间,但只有在编译的c#服务器端文件发生更改时才会生效。

编辑:我已经知道在项目目录中tsconfig.json的简单存在将防止保存编译,即使配置文件为空。

现在可以修正某种方式吗?

这是我tsconfig.json的内容:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "diagnostics": true 
    }, 
    "include": [ 
    "**/*.ts" 
    ], 
    "exclude": [ 
    "node_modules" 
    ] 
} 

编辑2:我也尝试:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false, 
    "diagnostics": true 
    }, 
    "filesGlob": [ 
    "**/*.ts" 
    ], 
    "exclude": [ 
    "node_modules" 
    ] 
} 

,并没有做任何事情。

+2

我有完全相同的问题。此外,自安装Update 3和Typescript 2.0.3以来,智能感知不再有效。任何人都有解决方案? – Bluesight

回答

6

我卸载的Visual Studio 2015和打字稿2.0.3。然后我重新安装了Visual Studio 2015.打开我的解决方案并检查了Typescript 1.8.3后,我安装了Typescript 2.0.3并在“compilerOptions”之前添加了“compileOnSave”。从那以后它对我有用。添加此选项后,您需要重新启动Visual Studio。

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    ... 
} 
+3

您需要重新启动Visual Studio!那是一个小屁屁手!谢谢@Bluesight – doker

+0

不能在这里工作:( –

2

添加"compileOnSave":truetsconfig.json应该做的伎俩:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    ... 
+0

我也这么认为,但这是一个默认选项,它不起作用。 – doker

相关问题