在 tsconfig.json 中保存时编译对新文件的工作方式与对现有文件的工作方式不同
Compile on save in tsconfig.json works differently for new files than it does for existing files
所以我最近一直在试验 Angular 及其功能。其中之一是 tsconfig.json
中的 CompileOnSave
功能,具有以下设置:
"outDir": "./dist/out-tsc",
"watch": true,
一切正常,但是,我发现添加新文件和修改现有文件之间存在不同的行为。在这两种情况下,文件修改都会编译到 ./dist/out-tsc
文件夹中。都好。但是,在添加新文件时,编译器还会在同一文件夹中生成一个 .js 文件及其对应的映射文件。这令人困惑。这是设计使然吗?我应该手动删除它们还是可以自动删除?我的问题类似于
How can I get the Typescript compiler to output the compiled js to a different directory?
但是,我已经配置了 outDir
属性。我使用的是 Visual Studio 2019。请从项目目录的一部分中查看下面的屏幕截图。 api.component.ts
是一个现有文件,其修改被编译到 ./dist/out-tsc
目录中。 file.ts
、file1.ts
和 file2.ts
是新文件,它们似乎被编译到创建它们的文件夹以及 ./dist-out-tsc
文件夹中。我的 Angular 版本是 8.3.14。
screenprint from visual studio
我的 tsconfig.json 看起来像这样:
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "./",
"module": "esnext",
"outDir": "./dist/out-tsc",
"watch": true,
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
我通过将其添加到我的 .csproj 文件中解决了我的问题。但是,我想强调的是,Visual Studio 中已关闭保存时编译并重新启动 visual studio。这就是为什么我措手不及。我猜这还不够。
<PropertyGroup>
<TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
</PropertyGroup>
所以我最近一直在试验 Angular 及其功能。其中之一是 tsconfig.json
中的 CompileOnSave
功能,具有以下设置:
"outDir": "./dist/out-tsc",
"watch": true,
一切正常,但是,我发现添加新文件和修改现有文件之间存在不同的行为。在这两种情况下,文件修改都会编译到 ./dist/out-tsc
文件夹中。都好。但是,在添加新文件时,编译器还会在同一文件夹中生成一个 .js 文件及其对应的映射文件。这令人困惑。这是设计使然吗?我应该手动删除它们还是可以自动删除?我的问题类似于
How can I get the Typescript compiler to output the compiled js to a different directory?
但是,我已经配置了 outDir
属性。我使用的是 Visual Studio 2019。请从项目目录的一部分中查看下面的屏幕截图。 api.component.ts
是一个现有文件,其修改被编译到 ./dist/out-tsc
目录中。 file.ts
、file1.ts
和 file2.ts
是新文件,它们似乎被编译到创建它们的文件夹以及 ./dist-out-tsc
文件夹中。我的 Angular 版本是 8.3.14。
screenprint from visual studio
我的 tsconfig.json 看起来像这样:
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "./",
"module": "esnext",
"outDir": "./dist/out-tsc",
"watch": true,
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
我通过将其添加到我的 .csproj 文件中解决了我的问题。但是,我想强调的是,Visual Studio 中已关闭保存时编译并重新启动 visual studio。这就是为什么我措手不及。我猜这还不够。
<PropertyGroup>
<TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled>
</PropertyGroup>