当 tsconfig.json 位于项目中时,保存时的 Typescript 编译不起作用

2024-04-09

当我保存时,我无法使 Visual Studio 将打字稿编译为 js。

我有一个xproj(带有net框架的asp.net core) 适用于 Visual studio 2015 更新 3 的 TypeScript 2.0.3 工具。

我已尝试启用"watch" : true在 tsconfig.json 中,但它表示不支持当前主机。

我转到“工具”>“选项”>“文本编辑器”>“TypeScript”>“项目”并启用“自动编译不属于项目的 TypeScript 文件”

尽管如此,.ts 文件中的更改仅在编译期间才会反映在 .js 文件中,但仅当必须编译的 c# 服务器端文件发生更改时才会反映。

EDIT:我发现,即使配置文件为空,项目目录中简单存在 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"
  ]
}

EDIT 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 Studio 2015。打开解决方案并检查 Typescript 1.8.3 后,我安装了 Typescript 2.0.3 并在“compilerOptions”之前添加了“compileOnSave”。从那时起它对我有用。添加此选项后需要重新启动Visual Studio。

{
  "compileOnSave": true,
  "compilerOptions": {
  ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当 tsconfig.json 位于项目中时,保存时的 Typescript 编译不起作用 的相关文章

随机推荐