javascript - 无法将 sourceMap(.map) 文件移动到 Typescript 中的单独文件夹

标签 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 文件)保存在同一文件夹中,我在 tsconfig.json 中添加了以下配置

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

完成构建后,脚本文件连同 sourceMappingURL 注释一起成功生成。下面是 ma​​in.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 文件移动到其他文件夹。

最佳答案

有类似你的问题here .看看那里,您一定能够决定哪种方法符合您的愿望。

我认为将它们放在同一个文件夹中没有问题,而 *.js.map*.js 甚至不会被推送到你的仓库,只是 .gitignore 它们。我将 IntelliJ 与 Typescript 插件一起使用,这已经有助于防止我的眼睛干涸。 Here's how it looks like with my setup.

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

关于javascript - 无法将 sourceMap(.map) 文件移动到 Typescript 中的单独文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426004/

相关文章:

typescript - 编译 Angular2 ts 文件

javascript - LINQ SingleOrDefault() 等效项

javascript - 在 conf.js 的插件配置中使用 Protractor 参数值

javascript - 导入/导出模块 - Typescript

javascript - 运行第一个 div onclick

typescript - create-react-app --typescript 中编译的 js 文件的默认位置

reactjs - React : context hook, 将对象插入数组

javascript - Angular JS 2.0 将 typescript 编译为 javascript

javascript - Bootstrap 3 popover 隐藏内容仍然可以点击

javascript - 无法通过 Angular 2 数据绑定(bind)从服务访问返回的对象属性