我已经安装了最新版本的VS代码,我试图编译一个"app.ts“文件,以便我得到一个"app.js”和"app.js.map“。但是,当我编译项目时,它只创建"app.js“文件,而不创建映射文件。
在我的根文件夹中,我有一个".vscode“文件夹,其中包含以下"tsconfig.json”
{
"compilerOptions": {
"target": "es6",
"module": "amd",
"sourceMap": true
}和下面的"tasks.json“文件
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": ["app.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
}在根目录中我有我的"app.ts“文件
module App {
export class Person {
constructor(public name: string) { }
public log(showLog: boolean): void {
if (showLog) {
console.log("Der Name des Nutzers ist: " + this.name)
}
}
}
}
var person = new App.Person("Hallo Welt");
person.log(true);但是,当我用ctrl+shift+b编译它时,它只创建app.js文件,而不创建映射。
更新:我也尝试修改"tasks.json“
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// args is the HelloWorld program to compile.
"args": [" --sourcemap app.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}用但是,当我在下面的命令中使用命令promt时:
c:\Temp\vsCode\tsc --sourcemap app.ts然后一切正常工作,并创建映射文件。
发布于 2016-03-07 20:43:50
解决方案:修改args,它是一个带有字符串的数组,似乎是一种解决方案。
"args": ["--sourcemap", "app.ts"]当您想要将tsconfig.json用于编译选项时,需要使用以下task.json条目:
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
"windows": {
"command": "tsc",
"isShellCommand": true
},
// Tell the tsc compiler to use the tsconfig.json from the open folder.
"args": ["-p", "."],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}我修改了最初的文章并添加了"windows“设置,没有这些设置,vs代码似乎使用了一个旧的类型记录版本1.0.3.0,但我不知道为什么。
解决方案3-尝试查看Windows变量是否没有TypeScript版本1.0的条目--删除该条目并向最新版本中添加一个条目
发布于 2016-03-07 18:43:26
我认为根文件夹中应该有tsconfig.json (参见tsconfig)。不在.vscode文件夹中。
.vscode文件夹用于存储特定于可视音频代码(launch.json、settings.json、tasks.json)的配置文件。
https://stackoverflow.com/questions/35851224
复制相似问题