|
7 | 7 | ; You must not remove this notice, or any other, from this software. |
8 | 8 |
|
9 | 9 | (ns cljs.closure |
10 | | - "Compile ClojureScript to JavaScript with optimizations from Google |
11 | | - Closure Compiler producing runnable JavaScript. |
12 | | -
|
13 | | - The Closure Compiler (compiler.jar) must be on the classpath. |
14 | | -
|
15 | | - Use the 'build' function for end-to-end compilation. |
16 | | -
|
17 | | - build = find-sources -> add-dependencies -> compile -> optimize -> output |
18 | | -
|
19 | | - Two protocols are defined: IJavaScript and Compilable. The |
20 | | - Compilable protocol is satisfied by something which can return one |
21 | | - or more IJavaScripts. |
22 | | -
|
23 | | - With IJavaScript objects in hand, calling add-dependencies will |
24 | | - produce a sequence of IJavaScript objects which includes all |
25 | | - required dependencies from the Closure library and ClojureScript, |
26 | | - in dependency order. This function replaces the closurebuilder |
27 | | - tool. |
28 | | -
|
29 | | - The optimize function converts one or more IJavaScripts into a |
30 | | - single string of JavaScript source code using the Closure Compiler |
31 | | - API. |
32 | | -
|
33 | | - The produced output is either a single string of optimized |
34 | | - JavaScript or a deps file for use during development. |
35 | | - " |
36 | 10 | (:refer-clojure :exclude [compile]) |
37 | 11 | (:require [cljs.util :as util :refer [distinct-by]] |
38 | 12 | [cljs.core :as cljsm] |
|
861 | 835 | (let [url (deps/to-url (constants-filename opts))] |
862 | 836 | (javascript-file nil url [(str ana/constants-ns-sym)] ["cljs.core"]))) |
863 | 837 |
|
864 | | -;; Internally only REPLs use this. We do expose it in cljs.build.api - David |
865 | | - |
866 | 838 | (defn add-dependencies |
867 | | - "Given one or more IJavaScript objects in dependency order, produce |
| 839 | + "DEPRECATED: Given one or more IJavaScript objects in dependency order, produce |
868 | 840 | a new sequence of IJavaScript objects which includes the input list |
869 | 841 | plus all dependencies in dependency order." |
870 | 842 | [opts & inputs] |
|
1070 | 1042 | (str "#!" (or hashbang "/usr/bin/env node") "\n")) |
1071 | 1043 | (when preamble (preamble-from-paths preamble)))) |
1072 | 1044 |
|
1073 | | -(comment |
1074 | | - ;; add dependencies to literal js |
1075 | | - (add-dependencies {} "goog.provide('test.app');\ngoog.require('cljs.core');") |
1076 | | - (add-dependencies {} "goog.provide('test.app');\ngoog.require('goog.array');") |
1077 | | - (add-dependencies {} (str "goog.provide('test.app');\n" |
1078 | | - "goog.require('goog.array');\n" |
1079 | | - "goog.require('clojure.set');")) |
1080 | | - ;; add dependencies with external lib |
1081 | | - (add-dependencies {:libs ["closure/library/third_party/closure"]} |
1082 | | - (str "goog.provide('test.app');\n" |
1083 | | - "goog.require('goog.array');\n" |
1084 | | - "goog.require('goog.dom.query');")) |
1085 | | - ;; add dependencies with foreign lib |
1086 | | - (add-dependencies {:foreign-libs [{:file "samples/hello/src/hello/core.cljs" |
1087 | | - :provides ["example.lib"]}]} |
1088 | | - (str "goog.provide('test.app');\n" |
1089 | | - "goog.require('example.lib');\n")) |
1090 | | - ;; add dependencies to a JavaScriptFile record |
1091 | | - (add-dependencies {} (javascript-file false |
1092 | | - (deps/to-url "samples/hello/src/hello/core.cljs") |
1093 | | - ["hello.core"] |
1094 | | - ["goog.array"])) |
1095 | | - ) |
1096 | | - |
1097 | 1045 | ;; Optimize |
1098 | 1046 | ;; ======== |
1099 | 1047 |
|
|
1443 | 1391 |
|
1444 | 1392 | ;; optimize a ClojureScript form |
1445 | 1393 | (optimize {:optimizations :simple} (-compile '(def x 3) {})) |
1446 | | - |
1447 | | - ;; optimize a project |
1448 | | - (println (->> (-compile "samples/hello/src" {}) |
1449 | | - (apply add-dependencies {}) |
1450 | | - (apply optimize {:optimizations :simple :pretty-print true}))) |
1451 | 1394 | ) |
1452 | 1395 |
|
1453 | 1396 | ;; Output |
|
1977 | 1920 |
|
1978 | 1921 | :else (output-deps-file opts disk-sources)))) |
1979 | 1922 |
|
1980 | | -(comment |
1981 | | - |
1982 | | - ;; output unoptimized alone |
1983 | | - (output-unoptimized {} "goog.provide('test');\ngoog.require('cljs.core');\nalert('hello');\n") |
1984 | | - ;; output unoptimized with all dependencies |
1985 | | - (apply output-unoptimized {} |
1986 | | - (add-dependencies {} |
1987 | | - "goog.provide('test');\ngoog.require('cljs.core');\nalert('hello');\n")) |
1988 | | - ;; output unoptimized with external library |
1989 | | - (apply output-unoptimized {} |
1990 | | - (add-dependencies {:libs ["closure/library/third_party/closure"]} |
1991 | | - "goog.provide('test');\ngoog.require('cljs.core');\ngoog.require('goog.dom.query');\n")) |
1992 | | - ;; output unoptimized and write deps file to 'out/test.js' |
1993 | | - (output-unoptimized {:output-to "out/test.js"} |
1994 | | - "goog.provide('test');\ngoog.require('cljs.core');\nalert('hello');\n") |
1995 | | - ) |
1996 | | - |
1997 | | - |
1998 | 1923 | (defn get-upstream-deps* |
1999 | 1924 | "returns a merged map containing all upstream dependencies defined |
2000 | 1925 | by libraries on the classpath." |
|
0 commit comments