Skip to content

Commit 0daf21e

Browse files
committed
and cljs.closure/bundle? helper, :target :bundle is just sugar for :target :nodejs
and :nodejs-rt false
1 parent 8c7bc5e commit 0daf21e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,10 @@
16691669
(if (= :browser mode) "</script>');\n" "\n")))]
16701670
(map preload-str syms))))
16711671

1672+
(defn bundle? [opts]
1673+
(and (= :nodejs (:target opts))
1674+
(false? (:nodejs-rt opts))))
1675+
16721676
(defn output-main-file
16731677
"Output an entry point. In the non-modules case, opts is simply compiler
16741678
options. When emitting a module entry point, opts must contain :module-name."
@@ -1726,12 +1730,18 @@
17261730
[main])))))
17271731

17281732
(str (when (or (not module) (= :cljs-base (:module-name opts)))
1729-
(str "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n"
1733+
(str (when (bundle? opts)
1734+
"import {npmDeps} from \"./deps-rt.js\";")
1735+
"var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n"
17301736
"var CLOSURE_NO_DEPS = true;\n"
17311737
"if(typeof goog == \"undefined\") document.write('<script src=\"" asset-path "/goog/base.js\"></script>');\n"
17321738
"document.write('<script src=\"" asset-path "/goog/deps.js\"></script>');\n"
17331739
"document.write('<script src=\"" asset-path "/cljs_deps.js\"></script>');\n"
17341740
"document.write('<script>if (typeof goog == \"undefined\") console.warn(\"ClojureScript could not load :main, did you forget to specify :asset-path?\");</script>');\n"
1741+
(when (bundle? opts)
1742+
"window.require = function(lib) {\n"
1743+
" return npmDeps[lib];\n"
1744+
"}")
17351745
(apply str (preloads (:preloads opts) :browser))))
17361746
(apply str
17371747
(map (fn [entry]
@@ -2471,6 +2481,13 @@
24712481
(when (nil? (:nodejs-rt opts))
24722482
{:nodejs-rt true}))
24732483

2484+
;; :bundle is just sugar for
2485+
;; :target :nodejs + :nodejs-rt false
2486+
(= :bundle (:target opts))
2487+
(merge
2488+
{:target :nodejs
2489+
:nodejs-rt false})
2490+
24742491
(= optimizations :none)
24752492
(assoc
24762493
:cache-analysis (:cache-analysis opts true)

0 commit comments

Comments
 (0)