JavaScript的.MAP文件 - JavaScript源的地图 [英] Javascript .map files - javascript source maps

查看:204
本文介绍了JavaScript的.MAP文件 - JavaScript源的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我已经看到了 .js.map 随一些JavaScript库(如),并在我的头上,只是提出了几个问题:

Recently I have seen files with .js.map extension shipped with some JavaScript libraries (like Angular), and that just raised few questions in my head:


  • 这是什么呢?为什么在折角照顾人提供一个 .js.map 文件?

  • 我(作为一个JavaScript开发)如何可以使用 angular.min.js.map 文件?

  • 我应该关心创建 .js.map 文件我的JavaScript应用程序?

  • 它是如何获得创建?我看了看 angular.min.js.map ,它充满了奇怪的格式的字符串,所以我认为它不会手动创建。

  • What is it for? Why do the guys at Angular care to deliver a .js.map file?
  • How can I (as a JavaScript developer) use the angular.min.js.map file?
  • Should I care about creating .js.map files for my JavaScript applications?
  • How does it get created? I took a look at angular.min.js.map and it was filled with strange-formatted strings so I assume it's not created manually.

推荐答案

该.MAP文件是为已经缩小的JS和CSS文件。他们被称为SourceMaps。当你运行如下的文件,像angular.js文件,它需要pretty code线的千把它变成只有几行难看code的。我们希望,当要运送的code到生产,使用的是缩小的code,而不是完整,unminified版本。当你的应用程序是在生产中,并有一个错误,sourcemap将有助于把你的丑陋的文件,将让你看到code的原始版本。如果你没有足够的sourcemap,那么任何错误充其量难以理解。

The .map files are for js and css files that have been minified. They are called SourceMaps. When you minify a file, like the angular.js file, it takes thousands of lines of pretty code and turns it into only a few lines of ugly code. Hopefully, when you are shipping your code to production, you are using the minified code instead of the full, unminified version. When your app is in production, and has an error, the sourcemap will help take your ugly file, and will allow you to see the original version of the code. If you didn't have the sourcemap, then any error would seem cryptic at best.

同样的CSS文件。一旦你把一个SASS或更少的文件,并将其编译成CSS,它看上去一点也不像它的原始形式。如果启用sourcemaps,然后就可以看到,而不是修改状态文件的原始状态。

Same for CSS files. Once you take a SASS or LESS file and compile it to CSS, it looks nothing like it's original form. If you enable sourcemaps, then you can see the original state of the file, instead of the modified state.

因此​​,要回答你为了问题:

So, to answer you questions in order:


  • 这是什么呢?:要取消参考变丑code

  • 如何可以开发使用吗?您使用它进行调试生产应用程序。在开发模式下可以使用完整版的角的。在生产中,你可以使用精缩版。

  • 我应该关心创建js.map文件?如果你在乎能调试生产code更容易,那么,你应该这样做。

  • 它是如何获得创建?这是在构建时创建的。有建立一个可以建立你的.MAP文件你作为它的其他文件的工具。 <一href=\"https://github.com/gruntjs/grunt-contrib-uglify/issues/71\">https://github.com/gruntjs/grunt-contrib-uglify/issues/71

  • What is it for? To de-reference uglified code
  • How can a developer use it? You use it for debugging a production app. In development mode you can use the full version of Angular. In production, you would use the minified version.
  • Should I care about creating a js.map file? If you care about being able to debug production code easier, then yes, you should do it.
  • How does it get created? It is created at build time. There are build tools that can build your .map file for you as it does other files. https://github.com/gruntjs/grunt-contrib-uglify/issues/71

我希望这是有道理的。

I hope this makes sense.

这篇关于JavaScript的.MAP文件 - JavaScript源的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆