简体   繁体   English

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

[英]Unable to move sourceMap(.map) files to separate folders in Typescript

I'm using Sublime Typescript Plugin to transpile Typescript files.我正在使用 Sublime Typescript 插件来转换 Typescript 文件。

Project folder项目文件夹

在此处输入图片说明

I've done all the setup for a sample project with help of tsconfig.json(using Typescript 1.5V).我已经在 tsconfig.json(使用 Typescript 1.5V)的帮助下完成了示例项目的所有设置。 Below is my tsconfig.json下面是我的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":""
    }

}

To move all the sourceMap files into other folder(mapFiles) folder rather than keeping in all the files(.js and .map files) in same folder, I've added below config into tsconfig.json要将所有 sourceMap 文件移动到其他文件夹(mapFiles)文件夹中,而不是将所有文件(.js 和 .map 文件)保存在同一文件夹中,我已将以下配置添加到 tsconfig.json

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

After done the build, Script files are generated successfully along with sourceMappingURL comments.构建完成后,脚本文件与 sourceMappingURL 注释一起成功生成。 Below is the out of main.ts file.下面是main.ts文件。

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

But main.js.map file is not moved the respective folder(mapFiles).但是 main.js.map 文件没有移动到相应的文件夹(mapFiles)。 It is in same folder where the js file is generated.它位于生成 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.

Please let me know how to move sourceMap files to other folders on run-time.请让我知道如何在运行时将 sourceMap 文件移动到其他文件夹。

There is something similar to your question here .有类似于你的问题的东西在这里 Take a look there and you will certainly be able to decide what approach fits your wishes.看看那里,您一定能够决定哪种方法适合您的愿望。

I don't see a problem in leaving them both on the same folder whereas *.js.map and *.js won't even be pushed to your repo, just .gitignore them.我认为将它们放在同一个文件夹中没有问题,而*.js.map*.js甚至不会被推送到你的*.js.map ,只是.gitignore它们。 I use IntelliJ with the Typescript plugin, which already helps to keep my eyes from drying out.我使用 IntelliJ 和 Typescript 插件,这已经有助于防止我的眼睛变干。 Here's how it looks like with my setup.这是我的设置的样子。

If there is a reason to separate them and I am not aware of it, then you can write a task that separates them.如果有理由将它们分开而我不知道,那么您可以编写一个将它们分开的任务。 So keep "mapRoot":"mapFiles", "outDir": "js", in your tsconfig.json and add a script in package.json to move them.所以在你的 tsconfig.json 中保留"mapRoot":"mapFiles", "outDir": "js",并在 package.json 中添加一个脚本来移动它们。

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

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