获取源映射使用已评估的代码 [英] Getting source maps working with evaluated code

查看:93
本文介绍了获取源映射使用已评估的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个构建脚本,通过uglifyjs运行我的所有代码,执行一些花哨的缓存,最终在某些JavaScript文件上运行 eval(code)

I have a build script that runs all my code through uglifyjs, does a bunch of fancy caching stuff, and ultimately runs eval( code ) on some JavaScript files.

我正在尝试使用源地图,但只要我使用 eval ,我似乎无法使其正常工作。如果我使用< script src =...> 直接链接到文件,它可以正常工作。

I'm trying to get this whole process up and running with source maps, but I can't seem to get it working as long as I'm using eval. If I link to the files directly using <script src="..."> it works fine.

在我的 eval 代码中,我有:

code, blah blah blah
//@ sourceMappingURL=/cache/618a67795c7460184bd9b99020cbb9fd.map

然后在那 .map 文件,我有:

{
      "version"  : 3
    , "file"     : "618a67795c7460184bd9b99020cbb9fd.map"
    , "sources"  : ["/js/Parallax-JS/js/parallax-2.js"]
    , "names"    : [
          "a"
        , "bunch"
        , "of"
        , "variable"
        , "names"
    ]
    , "mappings" : "... LONG MAP ..."
}



<我已经尝试在最后输入 // @ sourceURL = ,这至少给了我正确的文件名,但仍然没有可读源。

I've tried putting //@ sourceURL= at the end instead, and that at least gives me the correct file name, but still no readable source.

任何想法?在Chrome 25(dev)和26(金丝雀)中进行测试

Any ideas? Testing in Chrome 25 (dev) and 26 (canary)

推荐答案

我遇到了类似的问题,解决方案似乎正在使用内联SourceMaps(SourceMap的DataURL)。

I had a similar problem and the solution seem to be using an inlined SourceMaps (DataURL of a SourceMap).

以下是一个示例:


eval(blah blah \ n // @ sourceMappingURL = data:application / json; base64,...);

好像你不能从eval引用外部资源。

Seems like you can't reference external resources from an eval.

我认为您还需要使用 sourcesContent 将源代码插入SourceMap。

I think you also need to use sourcesContent to insert the source code into the SourceMap.

经过测试使用Chrome 32。

Tested with Chrome 32.

这篇关于获取源映射使用已评估的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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