我使用Figwheel和Node,并发现时间戳源映射存在一个bug。当设置{{:source-map-timestamp}}编译器标志时,{{sourceMappingURL}}被设置为{{source.js.map?timestamp}}。
这在浏览器中运行良好,但在从文件系统中加载文件时在Node中损坏。看起来一个简单的解决方案是检查{{:target}}是否为{{:node}},然后输出类似于{{source.js.timestamp.map}}的值,并直接使用它作为{{sourceMappingURL}}的值。
这是我在{{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
(attrs-one 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=")
"")
(if (and (true? (:source-map-timestamp opts))
(:source-map-url opts)
attrs-one (:source-map-url opts)
(str "?rel=" timestamp)
")"))
{: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))}}))))