Multiple ClojureScript (sub)projects with shared CLJS libraries per single clojure project

496 views
Skip to first unread message

Tom Krestle

unread,
Mar 30, 2012, 12:16:36 PM3/30/12
to clo...@googlegroups.com
Hi,

The project I envision would consist of multiple completely independent conglomerates of CLJS scripts compiled into several separate final production .js with one single Clojure server.
The reason for that is:
1. Smaller size of .js to load at each stage
2. Each time a browser transitions from one such a conglomerate to another one, it has a chance to reset its memory.
3. Better management of the overall project and easier sharing of components across projects.

Do you think this approach makes sense overall?

Every single lein plugin and tools I encountered (including ClojureScript One) support single .JS out of all CLJS scripts in src/. Is there an easy way to leverage this? Or I'll have to build my own support of separate compilation of CLJS subfolders into separate production .JS files (and support for shared CLJS libraries)?

Thank you,
Tom

Stuart Sierra

unread,
Mar 30, 2012, 1:46:02 PM3/30/12
to clo...@googlegroups.com
At Relevance we are working on a project with just this structure. The project has a custom build script that produces mulitple advanced-mode-compiled .js files.

We have not developed anything that would be generally reusable, but it's not hard to create custom code to do this. The ClojureScript compiler can be called just like any other function. Look at the compilation code in ClojureScript One for examples.

-S

Mark Rathwell

unread,
Mar 30, 2012, 1:49:29 PM3/30/12
to clo...@googlegroups.com
I haven't tried yet, but lein-cljsbuild [1] is meant to support
multiple builds, and I believe something like the below config would
be what you are looking for:

:cljsbuild {
:builds
[{:source-path "src/cljs/project1"
:compiler {:output-to "resources/public/cljs/script1.js"
:externs ["externs/jquery.js"]
:optimizations :advanced
:pretty-print true}}
{:source-path "src/cljs/project2"
:compiler {:output-to "resources/public/cljs/script2.js"
:externs ["externs/jquery.js"]
:optimizations :advanced
:pretty-print true}}]}

[1] https://github.com/emezeske/lein-cljsbuild

- Mark

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Evan Mezeske

unread,
Mar 30, 2012, 2:45:18 PM3/30/12
to clo...@googlegroups.com
I can confirm Mark Rathewell's note; that's part of what lein-cljsbuild is meant to do.

With his configuration, the script1.js and script2.js files would both be built, and each would only contain the code from the project1 or project2 directories, respectively (unless they require code from outside namespaces, then that would be included too).

Running "lein cljsbuild once" would build both cljs subprojects in parallel, and "lein cljsbuild auto" would watch both for modifications and rebuild them as needed.

-Evan

Robert Stuttaford

unread,
May 13, 2012, 8:22:43 AM5/13/12
to clo...@googlegroups.com
I'm planning a base app which loads and unloads cljs mini-apps into the main app, one at a time. The problem domain is such that there are simply too many mini-apps to load upfront.

Is lein-cljs build clever enough to generate exports and externs so that these modules can talk to each other? For second prize, is it possible to metadatum stuff and have lein-cljs generate an appropriate externs file?
Reply all
Reply to author
Forward
0 new messages