                           (IllegalArgumentException.
                             (str "Could not find namespace " entry-sym)))))
                     [sources []] entries)]
+              ;; add inputs to module
               (doseq [^SourceFile module-source module-sources]
                 (.add js-module module-source))
-              [sources' (conj modules js-module)]))
-          [sources [base-module]] (:modules opts))]
-    ;; add anything left to base
+              [sources'
+               (conj ret
+                 [name (assoc module-desc :closure-module js-module)])]))
+          [sources []] (sort-modules (add-cljs-base-module (:modules opts))))
+        cljs-base-closure-module (get-in modules [:cljs-base :closure-module])]
+    ;; add anything left to :cljs-base module
     (doseq [^SourceFile source sources']
-      (.add base-module source))
+      (.add ^JSModule cljs-base-closure-module source))
     modules))
 
 (comment

                           (when (some #{entry} (:provides source))
                             source))
                        sources)))
        base-module (JSModule. "cljs_base")
        [sources' modules]
        (reduce
          (fn [[sources modules] [name module-desc]]
            (let [{:keys [entries output-to depends-on]} module-desc
                  js-module (JSModule. (clojure.core/name name))
                  [sources' module-sources]
                  (reduce
                    (fn [[sources ret] entry-sym]
                      (if-let [entry (find-entry sources entry-sym)]

     :output-to "out/hello.js"
     :source-map true})

  (let [modules
        (build-modules
          [(map->javascript-file
             (ana/parse-ns 'cljs.core (io/file "out/cljs/core.js") nil))
           (map->javascript-file
             (ana/parse-ns 'cljs.reader (io/file "out/cljs/reader.js") nil))]
          {:optimizations  :advanced
           :output-dir     "out"
           :cache-analysis true
           :modules        {:core
                            {:output-to "out/modules/core.js"
                             :entries   '#{cljs.core}}
                            :landing
                            {:output-to  "out/modules/reader.js"
                             :entries    '#{cljs.reader}
                             :depends-on #{:core}}}})]
    modules)
  )

(defn optimize
