简体   繁体   English

VS Code TypeScript SourceMap创建

[英]VS Code TypeScript SourceMap creation

I've installed newest Version of VS Code and I try to compile a "app.ts" file so that I get a "app.js" and "app.js.map". 我已经安装了最新版本的VS Code,我尝试编译“app.ts”文件,以便获得“app.js”和“app.js.map”。 But when I compile the project it only creates the "app.js" file and no mapping file. 但是当我编译项目时,它只创建“app.js”文件而没有映射文件。

in my root folder I've a ".vscode" folder with the following "tsconfig.json" 在我的根文件夹中,我有一个“.vscode”文件夹,其中包含以下“tsconfig.json”

{
 "compilerOptions": {
     "target": "es6",
     "module": "amd",
     "sourceMap": true 
}

and the following the "tasks.json" file 以及“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"
   }
}

and in the root directory I've my "app.ts" file 并在根目录中我有我的“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);

but when I compile it with ctrl+shift+b it only creates the app.js file and no mapping. 但是当我使用ctrl + shift + b编译它时,它只会创建app.js文件并且没有映射。

Update: I've also tried to modify the "tasks.json" 更新:我也尝试修改“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"
}

with --sourcemap Argument but it doesn't work. 使用--sourcemap参数但它不起作用。 But when I use the command promt with the following command: 但是当我使用命令promt时使用以下命令:

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

then everything works fine and the mapping files are created. 然后一切正常,并创建映射文件。

I think you should have tsconfig.json in the root folder (see tsconfig ). 我认为你应该在根文件夹中有tsconfig.json(参见tsconfig )。 Not in the .vscode folder. 不在.vscode文件夹中。

.vscode folder is ment for storing config files that are specific to visual sudio code (launch.json, settings.json, tasks.json). .vscode文件夹用于存储特定于visual sudio代码的配置文件(launch.json,settings.json,tasks.json)。

The Solution: modify the args, its an array with strings, seems to be one solution 解决方案:修改args,它是一个带字符串的数组,似乎是一个解决方案

"args": ["--sourcemap", "app.ts"]

alternate Solution, when you want to use your tsconfig.json for compile options you need to use this task.json entry: 备用解决方案,如果要将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"
}

I've modified the original post and added the "windows" Settings, without this settings it seems that vs code uses a old typescript version 1.0.3.0 but I don't know why. 我修改了原始帖子并添加了“windows”设置,没有这个设置似乎vs代码使用旧的打字稿版本1.0.3.0但我不知道为什么。

Solution Number 3 - Try to look if the Windows PATH variable don't has a entry to TypeScript Version 1.0 - remove this entry and add a entry to the newest version 解决方案编号3 - 尝试查看Windows PATH变量是否没有TypeScript版本1.0的条目 - 删除此条目并将条目添加到最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM