哪个是sourcemappingurl的基本网址:相对来自html还是js? [英] Which is the base url of sourcemappingurl: relative from html or js?

查看:213
本文介绍了哪个是sourcemappingurl的基本网址:相对来自html还是js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在html文件的子目录中有一个带有source-map的js文件。

Suppose that there is a js file with source-map in subdirectory of a html file.


  • index.html(使用js / myjs.js)

  • js / myjs.js

  • js / myjs.js.map

然后是myjs.js的sourceMappingURL评论?

then which is the sourceMappingURL comment of myjs.js ?

//# sourceMappingURL=myjs.js.map

//# sourceMappingURL=js/myjs.js.map


推荐答案

我查找规范

当源映射网址时不是绝对的,那么它是相对于生成的代码的源起源。源来源由以下情况之一确定:

When the source mapping URL is not absolute, then it is relative to the generated code’s "source origin". The source origin is determined by one of the following cases:


  • 如果生成的源与
    的脚本元素无关具有src属性,并且在
    生成的代码中存在//#sourceURL注释,该注释应用于确定源
    来源。注意:以前,这是// @ sourceURL,与// @
    sourceMappingURL一样,接受两者都是合理的,但//#是
    首选。

  • 如果生成的代码与脚本元素
    相关联,并且脚本元素具有src属性,则脚本元素的
    的src属性将是来源。

  • 如果生成的代码
    与脚本元素相关联,并且脚本元素没有
    具有src属性,那么源源代码将是页面的
    来源。

  • 如果使用
    eval()函数或通过新函数()将生成的代码作为字符串求值,那么源的原点将是
    页面的来源。

  • If the generated source is not associated with a script element that has a "src" attribute and there exists a //# sourceURL comment in the generated code, that comment should be used to determine the source origin. Note: Previously, this was "//@ sourceURL", as with "//@ sourceMappingURL", it is reasonable to accept both but //# is preferred.
  • If the generated code is associated with a script element and the script element has a "src" attribute, the "src" attribute of the script element will be the source origin.
  • If the generated code is associated with a script element and the script element does not have a "src" attribute, then the source origin will be the page’s origin.
  • If the generated code is being evaluated as a string with the eval() function or via new Function(), then the source origin will be the page’s origin.

因此,如果您使用< script src =js / myjs.js> 在index.html中使用了js / myjs.js.map。

So if you use <script src="js/myjs.js"> in index.html the js/myjs.js.map is used.

这篇关于哪个是sourcemappingurl的基本网址:相对来自html还是js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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