Hello,

I'm trying to package all our trackers code (think Google analytics and the 
likes) into different splits so that they don't make base JS package too 
big and don't slow down time to interactive. Good idea, right ?

Our strategy is basically to write the trackers code in Javascript first 
with Google Closure compiler in mind (goog.provide(), goog.require() etc.) 
and add those libs to our CLJS project and also package it as a standalone 
Javascript file for others non-CLJS project. So far it works really well, 
until now that I'm trying to code-split them.

My first experiment fails because the code of the split ends up in the base 
package instead, even though the split file is created. But this split file 
is empty. Here's the configuration:

Linux
Boot 2.7.1 with boot-cljs 2.1.4
Clojure 1.9
ClojureScript  1.9.946
Java 8 (openjdk version "1.8.0_144")

CLJS compiler options:

```
{:main           "yoda.core"
 :libs           ["trackers/google_analytics.js" ] ;; lot of trackers 
here...
 :modules        {:google-analytics {:entries   
'#{yoda.tracking.google-analytics} ;; cljs namespace that wraps the call to 
JS tracker, to be able to call `(loader/set-loaded! :google-analytics)`
                                     :output-to "js/google-analytics.js"}}
 :asset-path     "/yd/js/main.out"
 :optimizations  :simple
 :source-map     true
 :parallel-build true
 :verbose        true}
```

I use the modules like this in the CLJS code:

```
;; CLJS wrapper namespace
(ns yoda.tracking.google-analytics
  (:require [cljs.loader :as loader]
            [trackers.google-analytics :as ga]))

(defn start [ga-tracking-id entity]
  (ga/start ga-tracking-id entity))

(loader/set-loaded! :google-analytics)

;; Code that lazy-loads it somewhere else
(loader/load :google-analytics
             (fn []
               ((resolve 'yoda.tracking.google-analytics/start) 
ga-tracking-id entity)))
```

It seems to work when I look at the browser console:
log:Module loaded: cljs_base
log:Module loaded: google_analytics

But when I examine the cljs_base.js and google_analytics.js files, the 
problem appears: cljs_base.js contains the code of my CLJS wrapper 
namespace, and google_analytics.js is empty (apart from the comment for 
source-map).

With the `:verbose true` option it looks like the CLJS compiler does the 
work properly:
Building module :google-analytics
# ... several entries ...
adding entry [trackers.google-analytics] # the JS code
adding entry (yoda.tracking.google-analytics) # our CLJS wrapper namespace
module :google-analytics depends on :cljs-base

Furthermore I expected the google_analytics.js to be loaded with a network 
request, but there's only the request to load cljs_base.js.

Is it because of cross module code motion ? It seems that the code of the 
CLJS tracker is moved to the main module, but I don't understand why.

Thanks in advance for your help.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.

Reply via email to