[英]VS Code TypeScript SourceMap creation
我已經安裝了最新版本的VS Code,我嘗試編譯“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"
}
使用--sourcemap參數但它不起作用。 但是當我使用命令promt時使用以下命令:
c:\Temp\vsCode\tsc --sourcemap app.ts
然后一切正常,並創建映射文件。
我認為你應該在根文件夾中有tsconfig.json(參見tsconfig )。 不在.vscode文件夾中。
.vscode文件夾用於存儲特定於visual sudio代碼的配置文件(launch.json,settings.json,tasks.json)。
解決方案:修改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 PATH變量是否沒有TypeScript版本1.0的條目 - 刪除此條目並將條目添加到最新版本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.