繁体   English   中英

VS Code TypeScript SourceMap创建

[英]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.

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