|
1669 | 1669 | (if (= :browser mode) "</script>');\n" "\n")))]
|
1670 | 1670 | (map preload-str syms))))
|
1671 | 1671 |
|
| 1672 | +(defn bundle? [opts] |
| 1673 | + (and (= :nodejs (:target opts)) |
| 1674 | + (false? (:nodejs-rt opts)))) |
| 1675 | + |
1672 | 1676 | (defn output-main-file
|
1673 | 1677 | "Output an entry point. In the non-modules case, opts is simply compiler
|
1674 | 1678 | options. When emitting a module entry point, opts must contain :module-name."
|
|
1726 | 1730 | [main])))))
|
1727 | 1731 |
|
1728 | 1732 | (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" |
1730 | 1736 | "var CLOSURE_NO_DEPS = true;\n"
|
1731 | 1737 | "if(typeof goog == \"undefined\") document.write('<script src=\"" asset-path "/goog/base.js\"></script>');\n"
|
1732 | 1738 | "document.write('<script src=\"" asset-path "/goog/deps.js\"></script>');\n"
|
1733 | 1739 | "document.write('<script src=\"" asset-path "/cljs_deps.js\"></script>');\n"
|
1734 | 1740 | "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 | + "}") |
1735 | 1745 | (apply str (preloads (:preloads opts) :browser))))
|
1736 | 1746 | (apply str
|
1737 | 1747 | (map (fn [entry]
|
|
2471 | 2481 | (when (nil? (:nodejs-rt opts))
|
2472 | 2482 | {:nodejs-rt true}))
|
2473 | 2483 |
|
| 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 | + |
2474 | 2491 | (= optimizations :none)
|
2475 | 2492 | (assoc
|
2476 | 2493 | :cache-analysis (:cache-analysis opts true)
|
|
0 commit comments