|
1478 | 1478 | (if (= :browser mode) "</script>');\n" "\n")))]
|
1479 | 1479 | (map preload-str syms))))
|
1480 | 1480 |
|
1481 |
| -(defn output-main-file [opts] |
1482 |
| - (let [asset-path (or (:asset-path opts) |
| 1481 | +(defn output-main-file |
| 1482 | + "Output an entry point. In the non-modules case, opts is simply compiler |
| 1483 | + options. When emitting a module entry point opts must contain :module-name, |
| 1484 | + fully expanded :modules and :inputs (all compiler IJavaScript input sources)." |
| 1485 | + [opts] |
| 1486 | + (assert (or (not (contains? opts :module-name)) |
| 1487 | + (get (:modules opts) (:module-name opts))) |
| 1488 | + (str "Module " (:module-name opts) " does not exist")) |
| 1489 | + (let [module (get (:modules opts) (:module-name opts)) |
| 1490 | + asset-path (or (:asset-path opts) |
1483 | 1491 | (util/output-directory opts))
|
1484 | 1492 | closure-defines (json/write-str (:closure-defines opts))]
|
1485 | 1493 | (case (:target opts)
|
1486 | 1494 | :nodejs
|
1487 |
| - (output-one-file opts |
| 1495 | + (output-one-file |
| 1496 | + (merge opts |
| 1497 | + (when module |
| 1498 | + {:output-to (:output-to module)})) |
1488 | 1499 | (add-header opts
|
1489 |
| - (str "var path = require(\"path\");\n" |
1490 |
| - "try {\n" |
1491 |
| - " require(\"source-map-support\").install();\n" |
1492 |
| - "} catch(err) {\n" |
1493 |
| - "}\n" |
1494 |
| - "require(path.join(path.resolve(\".\"),\"" asset-path "\",\"goog\",\"bootstrap\",\"nodejs.js\"));\n" |
1495 |
| - "require(path.join(path.resolve(\".\"),\"" asset-path "\",\"cljs_deps.js\"));\n" |
1496 |
| - "goog.global.CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" |
1497 |
| - (apply str (preloads (:preloads opts))) |
1498 |
| - (apply str |
1499 |
| - (map (fn [entry] |
1500 |
| - (str "goog.require(\"" (comp/munge entry) "\");\n")) |
1501 |
| - (if-let [entries (:entries opts)] |
1502 |
| - entries |
1503 |
| - [(:main opts)]))) |
| 1500 | + (str (when (or (not module) (= :cljs-base (:module-name opts))) |
| 1501 | + (str "var path = require(\"path\");\n" |
| 1502 | + "try {\n" |
| 1503 | + " require(\"source-map-support\").install();\n" |
| 1504 | + "} catch(err) {\n" |
| 1505 | + "}\n" |
| 1506 | + "require(path.join(path.resolve(\".\"),\"" asset-path "\",\"goog\",\"bootstrap\",\"nodejs.js\"));\n" |
| 1507 | + "require(path.join(path.resolve(\".\"),\"" asset-path "\",\"cljs_deps.js\"));\n" |
| 1508 | + "goog.global.CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" |
| 1509 | + (apply str (preloads (:preloads opts))))) |
| 1510 | + (apply str |
| 1511 | + (map (fn [entry] |
| 1512 | + (str "goog.require(\"" (comp/munge entry) "\");\n")) |
| 1513 | + (if-let [entries (when module (:entries module))] |
| 1514 | + entries |
| 1515 | + [(:main opts)]))) |
1504 | 1516 | "goog.require(\"cljs.nodejscli\");\n")))
|
1505 |
| - (output-one-file opts |
1506 |
| - (str "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" |
1507 |
| - "if(typeof goog == \"undefined\") document.write('<script src=\"" asset-path "/goog/base.js\"></script>');\n" |
1508 |
| - "document.write('<script src=\"" asset-path "/cljs_deps.js\"></script>');\n" |
1509 |
| - "document.write('<script>if (typeof goog == \"undefined\") console.warn(\"ClojureScript could not load :main, did you forget to specify :asset-path?\");</script>');\n" |
1510 |
| - (apply str (preloads (:preloads opts) :browser)) |
| 1517 | + (output-one-file |
| 1518 | + (merge opts |
| 1519 | + (when module |
| 1520 | + {:output-to (:output-to module)})) |
| 1521 | + (str (when (or (not module) (= :cljs-base (:module-name opts))) |
| 1522 | + (str "var CLOSURE_UNCOMPILED_DEFINES = " closure-defines ";\n" |
| 1523 | + "if(typeof goog == \"undefined\") document.write('<script src=\"" asset-path "/goog/base.js\"></script>');\n" |
| 1524 | + "document.write('<script src=\"" asset-path "/cljs_deps.js\"></script>');\n" |
| 1525 | + "document.write('<script>if (typeof goog == \"undefined\") console.warn(\"ClojureScript could not load :main, did you forget to specify :asset-path?\");</script>');\n" |
| 1526 | + (apply str (preloads (:preloads opts) :browser)))) |
1511 | 1527 | (apply str
|
1512 | 1528 | (map (fn [entry]
|
1513 | 1529 | (str "document.write('<script>goog.require(\"" (comp/munge entry)"\");</script>');\n"))
|
1514 |
| - (if-let [entries (:entries opts)] |
| 1530 | + (if-let [entries (when module (:entries module))] |
1515 | 1531 | entries
|
1516 | 1532 | (when-let [main (:main opts)]
|
1517 | 1533 | [main])))))))))
|
|
1771 | 1787 | (spit goog-deps (slurp (io/resource "goog/deps.js")))
|
1772 | 1788 | (cond
|
1773 | 1789 | modules
|
1774 |
| - (do |
| 1790 | + (let [modules' (module-graph/expand-modules modules sources)] |
1775 | 1791 | (output-deps)
|
1776 | 1792 | (doall
|
1777 | 1793 | (map
|
1778 |
| - (fn [[module-name {:keys [output-to entries]}]] |
| 1794 | + (fn [[module-name _]] |
1779 | 1795 | (output-main-file
|
1780 | 1796 | (merge opts
|
1781 |
| - {:output-to output-to :entries entries}))) |
| 1797 | + {:module-name module-name |
| 1798 | + :modules modules' |
| 1799 | + :inputs sources}))) |
1782 | 1800 | modules)))
|
1783 | 1801 |
|
1784 | 1802 | main
|
|
0 commit comments