bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 210 forks source link

Code-splitting(:modules) makes JS loaded asyncronously #635

Closed bbirec closed 6 years ago

bbirec commented 6 years ago

I am trying the code splitting feature #613 with 0.5.15-SNAPSHOT. However, it does not load scripts in synchronously.

(ns foo.core)

(defn ^:export main [name]
  (println "Hello" name))
<!DOCTYPE html>
<html lang="en">
  <body>
    <script src="js/compiled/out/cljs_base.js"></script>
    <script src="js/compiled/out/foo.js"></script>
    <script>
      foo.core.main("foo");
    </script>
  </body>
</html>

This outputs "foo is not defined" because foo.js is actually loaded after calling main. Is there any workaround?

Thank you.

bhauman commented 6 years ago

I think the common solution here is to have an initializing namespace that starts your application off. And require that as the base of your application. Otherwise you have to hook a loaded event that notifies you when the module has loaded. Which I have never done.

With most JS module systems you can not expect sync loading.

This really isn't a figwheel question though, (I don't think), so ...

Your going to want to direct this question to the Clojurians slack.

Sign up: http://clojurians.net Sign in: http://clojurians.slack.com

Channels of interest to this topic:

clojurescript