我正在使用 Figwheel 与 Node,并注意到了时间戳源代码映射的一个错误。当 {{:source-map-timestamp}} 编译器标志被设置为 {{源映射URL}} 时,设置为 {{source.js.map?timestamp}}。
这在浏览器中运行良好,但在从文件系统加载文件的 Node 中会破坏。看起来一个简单的解决方法是检查 {{:目标}} 是否为 {{:node}},并输出类似于 {{source.js.timestamp.map}} 的东西,并将其直接用作 {{源映射URL}} 的值。
这是我本地在 {{cljs.compiler/emit-source-map}} 中所做的更改,允许在使用时间戳时在 Node 上解析源代码映射。
{code:title=emit-source-map}
(defn emit-source-map [src dest sm-data opts]
(let [timestamp (System/currentTimeMillis)
filename (str (.getPath ^File dest)
(when (and
(true? (:source-map-timestamp opts))
(= (:target opts) :nodejs))
(str "." timestamp))
".map")
sm-file (io/file filename)]
(if-let [smap (:source-map-asset-path opts)]
(emits "\n//# sourceMappingURL=" smap)
(string/replace (util/path sm-file)
(str (util/path (io/file (:output-dir opts))))
"")
(if (and (true? (:source-map-timestamp opts))
(not= (:target opts) :nodejs))
(str
(if-not (string/index-of smap "?") "?" "&")
"rel=" timestamp)
""))
(emits "\n//# sourceMappingURL="
(or (:source-map-url opts) (.getName sm-file))
(if (and (true? (:source-map-timestamp opts))
(not= (:target opts) :nodejs))
(str "?rel=" timestamp)
"")))
(spit sm-file
(sm/encode {(url-path src) (:source-map sm-data)})
{:lines (+ (:gen-line sm-data) 2)}
:file (url-path dest)}
:source-map-path (:source-map-path opts)}
:source-map-timestamp (:source-map-timestamp opts)}
:source-map-pretty-print (:source-map-pretty-print opts)}
:relpaths {(util/path src)
 ;(util/ns->relpath (first (:provides opts)) (:ext opts)))}})