 (def ^Escaper js-escaper
   (SourceCodeEscapers/javascriptEscaper))
 
-(defn eval-load-sources [state sources]
+(defn generate-eval-js-output [state {:keys [sources] :as mod}]
   (->> sources
        (remove #{output/goog-base-id})
-       (map #(data/get-source-by-id state %))
-       (map (fn [{:keys [output-name] :as rc}]
-              (let [{:keys [js] :as output} (data/get-output! state rc)
-
-                    source-map?
-                    (output/has-source-map? output)]
-                (str "SHADOW_ENV.evalLoad(\"" output-name "\", " source-map? " , \"" (.escape js-escaper ^String js) "\");")
-                )))
-       (str/join "\n")))
-
-(defn flush-unoptimized-module-eval!
-  [{:keys [unoptimizable build-options] :as state}
-   {:keys [goog-base output-name prepend append sources web-worker] :as mod}
+       (reduce
+         (fn [state src-id]
+           (let [{:keys [output-name] :as rc} (data/get-source-by-id state src-id)
+                 {:keys [js eval-js] :as output} (data/get-output! state rc)]
+             (if eval-js
+               state
+               (let [source-map? (output/has-source-map? output)
+                     eval-js (str "SHADOW_ENV.evalLoad(\"" output-name "\", " source-map? " , \"" (.escape js-escaper ^String js) "\");")]
+                 (assoc-in state [:output src-id :eval-js] eval-js)))))
+         state)))
+
+(defn flush-unoptimized-module-eval
+  [{:keys [unoptimizable] :as state}
+   {:keys [goog-base prepend append sources web-worker] :as mod}
    target]
 
   (let [sources

          out)]

    (io/make-parents target)
    (spit target out)))

(defn flush-unoptimized-module!
  [state module target]
  (if (= :eval (get-in state [:shadow.build/config :devtools :loader-mode]))
    (flush-unoptimized-module-eval! state module target)
    (flush-unoptimized-module-fetch! state module target)))

(defn flush-unoptimized!
  [{:keys [build-modules] :as state}]

  ;; FIXME: this always flushes

                    default
                    []

                    (or release? (= :eval (get-in config [:devtools :loader-mode] :eval)))
                    [(str asset-path "/" (:output-name module))]

                    :else ;; dev-mode
