Visual Studio 不编译 TypeScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37262323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio not compiling TypeScript
提问by BanksySan
I have a Visual Studio project with a structure like so:
我有一个结构如下的 Visual Studio 项目:
My tsconfig.json
looks like:
我的tsconfig.json
样子:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"outDir": "../wwwroot/"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
However, VS isn't compiling the app.ts
into the wwwroot
folder.
但是,VS 不会将其编译app.ts
到wwwroot
文件夹中。
What am I missing?
我错过了什么?
采纳答案by David Pine
From within Visual Studio, Project >Properties >Build >ensure that the "Compile TypeScript on build" is checked:
在Visual Studio 中,Project >Properties >Build>确保选中“Compile TypeScript on build”:
Also, in your tsconfig.json
you should specify a rootDir
so that TypeScriptknows where to look for *.ts
files it should compile:
此外,tsconfig.json
您应该指定 arootDir
以便TypeScript知道在哪里查找*.ts
它应该编译的文件:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"outDir": "../wwwroot/",
"rootDir": "../wwwroot/"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
The details are called out on the TypeScriptpage hereand here.
Don't forget to actually build it. It isn't a file watcher scenario.
不要忘记实际构建它。这不是文件观察器方案。
回答by ericbowden
Try adding "compileOnSave": true
to your tsconfig.json
:
尝试添加"compileOnSave": true
到您的tsconfig.json
:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"outDir": "../wwwroot/"
},
"exclude": [
"node_modules",
"wwwroot"
],
"compileOnSave": true
}
It should compile every time you save now.
现在每次保存时它都应该编译。