首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VS代码TypeScript SourceMap创建

VS代码TypeScript SourceMap创建
EN

Stack Overflow用户
提问于 2016-03-07 18:31:09
回答 2查看 593关注 0票数 1

我已经安装了最新版本的VS代码,我试图编译一个"app.ts“文件,以便我得到一个"app.js”和"app.js.map“。但是,当我编译项目时,它只创建"app.js“文件,而不创建映射文件。

在我的根文件夹中,我有一个".vscode“文件夹,其中包含以下"tsconfig.json”

代码语言:javascript
复制
{
 "compilerOptions": {
     "target": "es6",
     "module": "amd",
     "sourceMap": true 
}

和下面的"tasks.json“文件

代码语言:javascript
复制
{
   "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“文件

代码语言:javascript
复制
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“

代码语言:javascript
复制
{
    "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时:

代码语言:javascript
复制
c:\Temp\vsCode\tsc --sourcemap app.ts

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-07 20:43:50

解决方案:修改args,它是一个带有字符串的数组,似乎是一种解决方案。

代码语言:javascript
复制
"args": ["--sourcemap", "app.ts"]

当您想要将tsconfig.json用于编译选项时,需要使用以下task.json条目:

代码语言:javascript
复制
{
    "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的条目--删除该条目并向最新版本中添加一个条目

票数 1
EN

Stack Overflow用户

发布于 2016-03-07 18:43:26

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35851224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档