tsconfig.json在项目中时,保存时的Typescript编译不起作用 [英] Typescript compile on save is not working when tsconfig.json is in project

查看:1240
本文介绍了tsconfig.json在项目中时,保存时的Typescript编译不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保存时,我无法使Visual Studio将打字稿编译运行到js.

我有一个xproj(带有net框架的asp.net核心) 用于Visual Studio 2015更新3.的TypeScript 2.0.3工具

我试图在tsconfig.json中启用"watch" : true,但是它说不支持当前主机.

我去了工具>选项>文字编辑器> TypeScript>项目和启用的自动编译不属于项目的TypeScript文件"

不过,.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"
  ]
}

它什么也没做.

解决方案

我卸载了Visual Studio 2015和Typescript 2.0.3.然后,我重新安装了Visual Studio2015.打开解决方案并检查Typescript 1.8.3之后,我安装了Typescript 2.0.3,并在"compilerOptions"之前添加了"compileOnSave".从那时起,它为我工作.添加此选项后,您需要重新启动Visual Studio.

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

I can't make visual studio to run typescript compilation to js when I save.

I have an xproj (asp.net core with net framework) TypeScript 2.0.3 tools for Visual studio 2015 update 3.

I have tried to enable "watch" : true in tsconfig.json but it says that current host is not supported.

I went to Tools > Options > Text Editor > TypeScript > Project and enabled "automatically compile TypeScript files which are not part of project"

Still, changes in .ts files will be reflected in .js files only during compilation, but only when there are changes in c# sever-side files that has to be compiled.

EDIT: I have figured out that simple existance of tsconfig.json in the project directory will prevent compilation on save even if the config file is empty.

Can that be fixed somehow currently?

This is the content of my 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"
  ]
}

EDIT 2: I also tried:

{
  "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"
  ]
}

and it didn't do anything.

解决方案

I uninstalled Visual Studio 2015 and Typescript 2.0.3. Then I reinstalled Visual Studio 2015. After opening my solution and checked Typescript 1.8.3, I installed Typescript 2.0.3 and added "compileOnSave" before "compilerOptions". Since then it works for me. You need to restart Visual Studio after adding this option.

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

这篇关于tsconfig.json在项目中时,保存时的Typescript编译不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆