|
65 | 65 | :id (string/replace (.getName file) #"\.cljs\.edn$" "")))) |
66 | 66 |
|
67 | 67 |
|
| 68 | +(def default-options {:sequences true, ; join consecutive statemets with the “comma operator” |
| 69 | + :properties true, ; optimize property access: a["foo"] → a.foo |
| 70 | + :dead_code true, ; discard unreachable code |
| 71 | + :drop_debugger true, ; discard “debugger” statements |
| 72 | + :unsafe false, ; some unsafe optimizations |
| 73 | + :conditionals true, ; optimize if-s and conditional expressions |
| 74 | + :comparisons true, ; optimize comparisons |
| 75 | + :evaluate true, ; evaluate constant expressions |
| 76 | + :booleans true, ; optimize boolean expressions |
| 77 | + :loops true, ; optimize loops |
| 78 | + :unused true, ; drop unused variables/functions |
| 79 | + :hoist_funs true, ; hoist function declarations |
| 80 | + :hoist_vars false, ; hoist variable declarations |
| 81 | + :if_return true, ; optimize if-s followed by return/continue |
| 82 | + :join_vars true, ; join var declarations |
| 83 | + :cascade true, ; try to cascade `right` into `left` in sequences |
| 84 | + :side_effects true, ; drop side-effect-free statements |
| 85 | + :warnings true, ; warn about potentially dangerous optimizations/code |
| 86 | + :global_defs {}, ; global definitions |
| 87 | + :mangle false ; mangle names |
| 88 | + }) |
| 89 | + |
68 | 90 | (core/deftask uglify |
69 | 91 | "Uglify JS code." |
70 | | - [;o options OPTS {} "option map to pass to Uglify. See http://lisperator.net/uglifyjs/compress. Also, you can pass :mangle true to mangle names" |
71 | | - ] |
| 92 | + [o options OPTS {} "option map to pass to Uglify. See http://lisperator.net/uglifyjs/compress. Also, you can pass :mangle true to mangle names."] |
| 93 | + |
72 | 94 | (util/info "Uglifying JS...\n") |
73 | 95 |
|
74 | | - (let [pod (make-pod) |
75 | | - tgt (core/tmp-dir!)] |
| 96 | + (println "OPTIONS ARE " options) |
| 97 | + |
| 98 | + (let [options (merge default-options options) |
| 99 | + pod (make-pod) |
| 100 | + tgt (core/tmp-dir!)] |
76 | 101 |
|
77 | 102 | ;; idea |
78 | 103 | ;; "intercept" files from the fileset, get cljs.edn files |
79 | 104 | ;; and use them (how) to find the final output file an minify it |
80 | 105 | ;; improvement : source maps (suported by UglifyJS2) |
81 | 106 |
|
| 107 | + |
82 | 108 | (core/with-pre-wrap [fs] |
83 | 109 | ;;(util/info "Task files : " (seq (core/input-files fs))) |
84 | 110 | ;;(util/info "no more task files\n") |
85 | | - (helpers/print-fileset fs) |
| 111 | + ;;(helpers/print-fileset fs) |
86 | 112 | (core/empty-dir! tgt) |
87 | 113 | ;; (println "Files :" (get-files fs)) ;; util/info does not work here ? |
88 | | - ;; (println "Intersting files " (find-mainfiles fs [".js"])) |
89 | | - ;; (println "Intersting files READABLE " (find-mainfiles fs [".js"])) |
| 114 | + ;; (println "Interesting files " (find-mainfiles fs [".js"])) |
| 115 | + ;; (println "Interesting files READABLE " (find-mainfiles fs [".js"])) |
90 | 116 | (let [js-files (find-mainfiles fs [".js"]) |
91 | 117 | edn-files (find-mainfiles fs [".cljs.edn"]) |
92 | 118 | edn-content (map read-cljs-edn edn-files) |
93 | 119 | ;;out-paths (-> edn-files :compiler-options :asset-path ) |
94 | 120 | out-paths (map (comp :asset-path :compiler-options) edn-content) |
95 | | - test-files (filter #(= "js/main.js" (:path %)) js-files)] |
96 | | - ;;(println "JS FILES _______________________________" (map :path js-files)) |
97 | | - ;; (println "JS FILES _______________________________" test-files) |
98 | | - ;; (println "OUT_PATHS "out-paths) |
99 | | - ;; (println "END-FILES _______________________________" edn-files) |
100 | | - ;; (println "EDN CONTENT _______________________________" edn-content) |
| 121 | + test-files (filter #(= "js/main.js" (:path %)) js-files) |
| 122 | + files test-files] |
| 123 | + |
| 124 | + ;; if-let here ?? |
101 | 125 |
|
102 | 126 | ;; run the minification in a pod, in a temp target directory |
103 | | - (doseq [f test-files :let [subf (copy f tgt) |
| 127 | + (doseq [f files :let [subf (copy f tgt) |
104 | 128 | txt (slurp subf) |
105 | 129 | path (core/tmp-path f)]] |
106 | | - |
107 | | - (println "EVAL " (pod/with-call-in @pod (nha.boot-uglify.impl/minify-str ~txt ~{}))) |
108 | | - ;;(spit subf (pod/with-call-in @pod (minify-str js-engine txt {}))) |
109 | | - )) |
| 130 | + (let [minified (pod/with-call-in @pod (nha.boot-uglify.impl/minify-str ~txt ~{}))] |
| 131 | + (println "Size before : " (count txt)) |
| 132 | + (println "Size after : " (count minified)) |
| 133 | + (spit subf minified))) |
| 134 | + (-> fs |
| 135 | + (core/rm files) |
| 136 | + (core/add-resource tgt) |
| 137 | + core/commit!)) |
110 | 138 | fs))) |
111 | 139 |
|
112 | 140 |
|
|
0 commit comments