David Nolen helped me via IRC.
Because React is a foreign library Google Closure doesn't know how to
re-arrange this and it gets moved to the base module, unless you explicitly
specify to which module it should belong. This solves the problem:
:modules {:source-paths ["src-cljs" "src-cljs-prod"]
:compiler
{:optimizations :advanced
:modules
{:cljs-base
{:output-to "resources/public/js-modules/cljs.js"}
:reagent
{:output-to "resources/public/js-modules/reagent.js"
:entries #{"cljsjs.react" "reagent.core"}}
:input
{:output-to
"resources/public/js-modules/new-recipe-form.js"
:entries #{"recipes.new-recipe-form"}
:depends-on #{:reagent}}
:hello
{:output-to
"resources/public/js-modules/hello.js"
:entries #{"recipes.main"}}}}}
I have defined one module that represent React and Reagent called :reagent. All
pages that depend on Reagent can then define their own module that :depends-on
the :reagent module.
cljs.js is now 235 kb,
reagent.js is 133 kb,
new-recipe-form.js 5 kb,
hello.js 49 bytes.
On Wednesday, March 11, 2015 at 6:25:02 PM UTC+1, Michiel Borkent wrote:
> Hello all,
>
> In my project I want to use Closure modules.
> I have defined this in my project.clj:
>
> :modules {:source-paths ["src-cljs" "src-cljs-prod"]
> :compiler
> {:optimizations :advanced
> :modules
> {:cljs-base
> {:output-to "resources/public/js-modules/cljs.js"}
> :input
> {:output-to
> "resources/public/js-modules/new-recipe-form.js"
> :entries #{"recipes.new-recipe-form"}}
> :hello
> {:output-to
> "resources/public/js-modules/hello.js"
> :entries #{"recipes.main"}}}}}
>
> The namespace recipes.new-recipe-form depends on React and Reagent, so I was
> hoping that Google Closure would move all of React into the module :input.
>
> When I compile with "lein cljsbuild once modules", I first get a
> java.io.FileNotFoundException. This problem is solved by creating the output
> dir manually:
>
> mkdir -p resources/public/js-modules
>
> When compilation finally succeeds, I see three .js files in my output dir:
>
> cljs.js: 368 KB
> hello.js 49 bytes
> new-recipe-form.js: 5KB
>
> When I look at the source of cljs.js, it starts with the entire React
> library. Unfortunately, because even when I want to run hello.js it needs
> cljs.js.
>
> The file recipes.main on which the module hello was based only contains this
> code:
>
> (ns recipes.main)
> (.log js/console (str "Hello world" (inc 10)))
>
> It's kind of bad that I need to load React before I can execute that code.
>
> If you have some suggestions, please respond.
>
> Kind regards,
>
> Michiel
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.