无法将sourceMap(.map)文件移动到Typescript

时间:2015-09-06 16:55:44

标签: javascript typescript typescript1.5

我使用Sublime Typescript插件来转换Typescript文件。

项目文件夹

enter image description here

我在tsconfig.json的帮助下完成了示例项目的所有设置(使用Typescript 1.5V)。以下是我的 tsconfig.json

{
    "compilerOptions": {
        "declaration":false,
        "mapRoot":"mapFiles",  
        "module": "commonjs",
        "noImplicitAny": true,
        "outDir": "js",
        "preserveConstEnums": true,
        "removeComments": true,
        "sourceMap": true,
        "sourceRoot": "mapFiles",
        "target":"es3",
        "watch":true,
        "rootDir":""
    }

}

要将所有sourceMap文件移动到其他文件夹(mapFiles)文件夹而不是保存在同一文件夹中的所有文件(.js和.map文件)中,我已将下面的config添加到tsconfig.json

"mapRoot":"mapFiles", 
"sourceMap": true,
"sourceRoot": "mapFiles",

完成构建后,将成功生成脚本文件以及sourceMappingURL注释。以下是 main.ts 文件。

var x = "will work";
//# sourceMappingURL=E:/type/projects/Examples/ex1/mapFiles/main.js.map

但是main.js.map文件没有移动到相应的文件夹(mapFiles)。它位于生成js文件的同一文件夹中。

Below is my understanding about .maps files:

1. Map files have the details about the respective .ts files with location of it.

2. it is used to track down .ts files easily.

请告诉我如何在运行时将sourceMap文件移动到其他文件夹。

1 个答案:

答案 0 :(得分:1)

类似于您的问题here。看看那里你肯定能够决定什么方法符合你的意愿。

我没有看到将它们放在同一个文件夹上的问题,而 *.js.map *.js 甚至不会被推送对你的回购,只需.gitignore他们。我将IntelliJ与Typescript插件一起使用,这有助于防止眼睛干涸。 enter image description here

如果有理由将它们分开并且我不知道它,那么你可以编写一个分隔它们的任务。所以在你的tsconfig.json中保留"mapRoot":"mapFiles", "outDir": "js",并在package.json中添加一个脚本来移动它们。