Organization of project file for multiple single-page apps

252 views
Skip to first unread message

Jonathon McKitrick

unread,
Sep 9, 2014, 6:21:05 AM9/9/14
to clojur...@googlegroups.com
I have about 6 pages with their own cljs code, and I'd also like to have dev, pre-prod, and prod compilation settings.

What's the best way to organize the project file to do this?

I currently have something like this:

:cljsbuild {:builds
{:outlines
{:source-paths ["src/cljs/outlines"] ;;"test/cljs"
:compiler {:output-to "resources/public/js/outlines.js"
:optimizations :simple
:pretty-print true
:preamble ["reagent/react.js"]}}
:speakers
{:source-paths ["src/cljs/speakers"]
:compiler {:output-to "resources/public/js/speakers.js"
:optimizations :simple
:pretty-print true
:preamble ["reagent/react.js"]}}
:outgoing
{:source-paths ["src/cljs/outgoing"]
:compiler {:output-to "resources/public/js/outgoing.js"
:optimizations :simple
:pretty-print true
:preamble ["reagent/react.js"]}}
:incoming
{:source-paths ["src/cljs/incoming"]
:compiler {:output-to "resources/public/js/incoming.js"
:externs ["js/externs.js"]
:optimizations :advanced
:pretty-print false
;;:output-dir "resources/public/js"
;;:source-map "resources/public/js/incoming.js.map"
:preamble ["jquery/jquery-2.1.1.min.js" "reagent/react.js"]}}
:home
{:source-paths ["src/cljs/home"]
:compiler {:output-to "resources/public/js/home.js"
:optimizations :simple
:pretty-print true
:preamble ["reagent/react.js"]}}
:confirm
{:source-paths ["src/cljs/confirm"]
:compiler {:output-to "resources/public/js/confirm.js"
:optimizations :simple
:pretty-print true
:preamble ["reagent/react.js"]}}
#_:outlines-testing
#_{:source-paths ["test/cljs" "src/cljs/outlines"]
:compiler {:preamble ["jquery/jquery-2.1.1.min.js" "reagent/react.js"]
:output-to "resources/public/js/outlines-testing.js"
:optimizations :simple
:pretty-print true}}}
#_:test-commands #_{"outlines-testing"
["phantomjs" :runner "resources/polyfill.js" "resources/public/js/outlines-testing.js"]}}

Zubair Quraishi

unread,
Sep 9, 2014, 9:10:41 AM9/9/14
to clojur...@googlegroups.com
You have it pretty much right, this is my project clj for Coils:

https://github.com/zubairq/coils/blob/master/project.clj

:profiles {
:dev
{
:source-paths ["src" "../srcdev"]
:cljsbuild
{
:builds
[
{
:source-paths ["src"]
:compiler {
:output-to "resources/public/main.js"
:optimizations :whitespace
:output-wrapper false
:externs ["resources/public/google_maps_api_v3_11.js"]
:pretty-print false
}
}
]

}
}

:base
{
:source-paths ["src"
"srcbase"
]
:cljsbuild
{
:builds
[
{
:source-paths ["src"]
:compiler {
:output-to "resources/public/main.js"
:optimizations :whitespace
:output-wrapper false
:externs ["resources/public/jquery-externs.js"
"resources/public/google_maps_api_v3_11.js"]
:pretty-print false
}
}
]

}
}


:test
{
:source-paths ["src" "../srctest"]
:cljsbuild
{
:builds
[
{
:source-paths ["src"]
:compiler {
:output-to "resources/public/main.js"
:optimizations :advanced
:output-wrapper false
:externs ["resources/public/jquery-externs.js"
"resources/public/google_maps_api_v3_11.js"
"resources/public/reactextern.js"]
:pretty-print false
:foreign-libs [{:file "https://maps.googleapis.com/maps/api/js?sensor=false"
:provides ["google.maps" "google.maps.MapTypeId"]}]
}
}
]

}
}

:prod
{
:source-paths ["src" "../srcprod"]
:cljsbuild
{
:builds
[
{
:source-paths ["src"]
:compiler {
:output-to "resources/public/main.js"
:optimizations :advanced
:output-wrapper false
:externs ["resources/public/jquery-externs.js"
"resources/public/google_maps_api_v3_11.js"
"resources/public/reactextern.js"]
:pretty-print false
:foreign-libs [{:file "https://maps.googleapis.com/maps/api/js?sensor=false"
:provides ["google.maps" "google.maps.MapTypeId"]}]
}
}
]

Zubair Quraishi

unread,
Sep 9, 2014, 9:12:07 AM9/9/14
to clojur...@googlegroups.com
Sorry, seems like I misunderstood. You have several projects in one file, not several profiles, is that correct?


On Tuesday, September 9, 2014 12:21:05 PM UTC+2, Jonathon McKitrick wrote:

Jonathon McKitrick

unread,
Sep 9, 2014, 10:03:37 AM9/9/14
to clojur...@googlegroups.com
Well, it's several destination .js files, basically.  And I also would like separate cljs-build profiles for different compiler settings.

I'm learning my way around cljs-build, and this is my next goal.


--
Jonathon McKitrick

--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/FzEJoy4yAK0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Gary Trakhman

unread,
Sep 9, 2014, 10:12:55 AM9/9/14
to clojur...@googlegroups.com
Maybe this is a stupid question, but why not share a single JS file across everything + have multiple entry-points?  Seems like you'd want to share _some_ code between the pages anyway.

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 clojurescrip...@googlegroups.com.

Jonathon McKitrick

unread,
Sep 9, 2014, 11:04:10 AM9/9/14
to clojur...@googlegroups.com
I guess that could be done, and yes, it does deal with code duplication.  I guess with optimizations on, there's no reason to worry about code size?


--
Jonathon McKitrick

Gary Trakhman

unread,
Sep 9, 2014, 11:05:26 AM9/9/14
to clojur...@googlegroups.com
Well, one cached possibly-larger file vs 6 slightly smaller ones.

Jonathon McKitrick

unread,
Sep 9, 2014, 11:17:54 AM9/9/14
to clojur...@googlegroups.com
That's a very good point.  The overhead of all the closure library stuff and CLJS code is much more than my client code.  That's a great idea....


--
Jonathon McKitrick

Ruslan Prokopchuk

unread,
Sep 12, 2014, 5:30:46 AM9/12/14
to clojur...@googlegroups.com
And even more, you can define component systems for every endpoint (reusing components between them!) using [com.palletops/leaven] (or port to CLJS [com.stuartsierra/component] or [im.chit/hara.component] by yourself) and start necessary one on each endpoint. As bonus, if some or all of endpoint will merge in one page in future, it will lead to really small changes in code to handle that merge.

вторник, 9 сентября 2014 г., 19:17:54 UTC+4 пользователь Jonathon McKitrick написал:
Reply all
Reply to author
Forward
0 new messages