Re: [ClojureScript] Problems with code-splitting

2018-02-05 Thread Khalid Jebbari
Bug filed: https://github.com/boot-clj/boot-cljs/issues/183

On Monday, February 5, 2018 at 5:22:58 PM UTC+1, Khalid Jebbari wrote:
>
> I managed to create a minimal reproduction repository. It’s definitely a 
> problem of Boot-cljs, not of the CLJS compiler itself.
>
> The repo (with problem statement and instructions): 
> https://github.com/DjebbZ/code-splitting-bug-boot-cljs
>
> Will post on boot-cljs issue too, it may help them spot the problem.
>
> On Saturday, February 3, 2018 at 2:37:18 PM UTC+1, Khalid Jebbari wrote:
>>
>> No I'm really lazy loading from another namespace, our `yoda.tracking` 
>> where all happens. This ns doesn't `require` at all the lazy loaded module, 
>> it just `resolve` it. I will work on a minimal repro case based on 
>> boot-cljs next week.
>>
>> Thanks for your attention.
>>
>

-- 
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.


Re: [ClojureScript] Problems with code-splitting

2018-02-05 Thread Khalid Jebbari
I managed to create a minimal reproduction repository. It’s definitely a 
problem of Boot-cljs, not of the CLJS compiler itself.

The repo (with problem statement and instructions): 
https://github.com/DjebbZ/code-splitting-bug-boot-cljs

Will post on boot-cljs issue too, it may help them spot the problem.

On Saturday, February 3, 2018 at 2:37:18 PM UTC+1, Khalid Jebbari wrote:
>
> No I'm really lazy loading from another namespace, our `yoda.tracking` 
> where all happens. This ns doesn't `require` at all the lazy loaded module, 
> it just `resolve` it. I will work on a minimal repro case based on 
> boot-cljs next week.
>
> Thanks for your attention.
>

-- 
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.


Re: [ClojureScript] Problems with code-splitting

2018-02-03 Thread Khalid Jebbari
No I'm really lazy loading from another namespace, our `yoda.tracking` where 
all happens. This ns doesn't `require` at all the lazy loaded module, it just 
`resolve` it. I will work on a minimal repro case based on boot-cljs next week.

Thanks for your attention.

-- 
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.


Re: [ClojureScript] Problems with code-splitting

2018-02-02 Thread David Nolen
I don't really understand your example. In your code snippet here it looks
like you're lazy loading the module from the module itself? If that was
unintentional, where is this lazy loading code happening?

Something a bit more minimal and more complete would be helpful.

David

On Mon, Jan 29, 2018 at 12:07 PM, Khalid Jebbari 
wrote:

> 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
>  :verbosetrue}
> ```
>
> 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.
>

-- 
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.


[ClojureScript] Problems with code-splitting

2018-01-29 Thread Khalid Jebbari
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
 :verbosetrue}
```

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.


[ClojureScript] Problems with code splitting

2018-01-29 Thread Khalid Jebbari
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
 :verbosetrue}
```

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 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.