【问题标题】:Source-map must be turned on for println to work?必须打开源映射才能使 println 工作?
【发布时间】:2014-06-07 09:02:15
【问题描述】:

这真的很奇怪。我的 project.clj 中有这个:

  :cljsbuild
  {:builds
   [{:id "async-tues-id"
     :source-paths ["src/async_tues/cljs"]
     :compiler {:optimizations :none
                :pretty-print false
                :output-dir "resources/compiler/"
                :output-to "resources/main.js"}}]}

注意这里没有开启source-map。

然后我的 cljs 文件中有这个:

(ns tues.page)
(enable-console-print!)

(println "hello from cljs!")

(println "hi from page.js")

lein cljsbuild 之后,浏览器将empty 行打印到控制台。我会添加更多 println 语句并执行它们...但没有文本。

然后我将它添加到 project.clj:

            :source-map true

新编译后,printlns 会根据需要显示实际文本!现在为什么 source-map 与println 的实际功能有任何关系??

【问题讨论】:

  • 这很奇怪,尝试发布一个git项目的URL,否则很难重现。
  • @Joaquin 所以你说这绝对是不是正常行为?还是 println 功能附加到源映射行为?
  • 它应该可以与 enable-console-print 一起正常工作!这绝对不正常。试试(.log js/console "hi") 看看它是否有效。
  • 指定 clojure、clojurescript 版本。添加可用于重现的github项目url。

标签: clojure clojurescript


【解决方案1】:

如果您使用“lein new reagent my-project”之类的内容来创建项目,您会在 prod/cljs/my-project/prod.cljs 中看到类似的内容。

(ns reagent.prod
  (:require [reagent.core :as core]))

;;ignore println statements in prod
(set! *print-fn* (fn [& _]))

(core/init!)

要指定 no :optimizations,我相信正确的值是 :whitespace,而不是 :none。 :simple 和 :advanced 也是有效的(在生产环境中始终使用 :advanced)。

这有点牵强,但也许打开 :source-maps 导致 :optimizations 默认为更合乎逻辑的非生产值(因为 :none 无效),这不知何故导致了 *print-fn* 的覆盖不会发生。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-24
    • 2023-03-31
    • 2011-05-07
    • 1970-01-01
    • 2020-06-23
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多