【问题标题】:VS Code TypeScript SourceMap creationVS Code TypeScript SourceMap 创建
【发布时间】:2016-03-07 18:31:09
【问题描述】:

我已经安装了最新版本的 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 参数,但它不起作用。但是当我使用带有以下命令的命令提示符时:

c:\Temp\vsCode\tsc --sourcemap app.ts

然后一切正常并创建映射文件。

【问题讨论】:

    标签: typescript visual-studio-code


    【解决方案1】:

    我认为您应该在根文件夹中有 tsconfig.json(请参阅tsconfig)。不在 .vscode 文件夹中。

    .vscode 文件夹用于存储特定于可视化音频代码(launch.json、settings.json、tasks.json)的配置文件。

    【讨论】:

    • 我试过了,结果一样,没有创建映射文件
    【解决方案2】:

    解决方案:修改 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 code 似乎使用的是旧的打字稿版本 1.0.3.0 但我不知道为什么。

    解决方案编号 3 - 尝试查看 Windows PATH 变量是否没有 TypeScript 版本 1.0 的条目 - 删除此条目并将条目添加到最新版本

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2016-08-08
      • 2019-11-16
      • 2019-09-29
      • 2017-06-24
      • 2021-05-31
      • 1970-01-01
      • 2016-11-01
      • 2019-08-08
      相关资源
      最近更新 更多