Fork me on GitHub
#clojurescript
<
2020-12-12
>
Takis_10:12:30

Hello i am looking for clojurescript(clojure like) alternatives,that generates less javascript code,even if not so optimized The reason i want this is to use it with MongoDB,clojurescript even if 2 lines of code generate like 2500 characters code and its very slow on MongoDB i found one that looks nice (the othes that i found look much smaller projects stopped years ago), but maybe there are more options https://github.com/Gozala/wisp

p-himik11:12:59

> clojurescript even if 2 lines of code generate like 2500 characters code Depends on what you use. Some functions and, I think, all CLJS data structures will generate a lot of code. But many won't.

p-himik11:12:31

E.g. this code compiles to 286 characters of JS in my setup:

(js/console.log (let [acc #js []]
                  (loop [i 10]
                    (when (pos? i)
                      (.push acc i)
                      (recur (dec i))))
                  acc))

Takis_12:12:28

hello thanks for the reply

Takis_12:12:52

i am new to clojurescript i compliled the code you sended like this :

Takis_12:12:55

clojure -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version \"1.10.741\"}}}' -m cljs.main -O advanced -c

Takis_12:12:02

and result is again so big

Takis_12:12:32

i want one clojure function to compile to one javascript function, i done it but the code is just too big

Takis_12:12:39

and in mongodb is very slow

Takis_12:12:05

i compile my code in wrong way? is there a better way to produce smaller js file?

Takis_12:12:11

i compiled this

Takis_12:12:27

(ns jstempproject.tempnamespace)

(defn ^:export myloop []
  (let [acc (js/Array)]
    (loop [i 10]
      (when (pos? i)
        (.push acc i)
        (recur (dec i)))) acc))

Takis_12:12:43

2583 characters

p-himik12:12:05

The default CLJS compiler might produce some polyfills that you don't need. I used shadow-cljs with these build parameters:

:compiler-options {:output-feature-set :es6}
                   :js-options       {:babel-preset-config {:modules "commonjs"
                                                            :targets "chrome > 70"}}

p-himik12:12:33

You can specify :compiler-options for the default CLJS compiler by using the -co flag but it didn't work for me. I don't know if you can specify :js-options.

Takis_12:12:55

i want to produce 1 js file

Takis_12:12:01

to run alone

p-himik12:12:20

Also, there might be other compiler options and js options that produce even a smaller result because I still see some small polyfill in there. Shadow-cljs does produce a single file.

Takis_12:12:52

ok thank you alot , i will try to compile with shadow-cljs also

Takis_12:12:13

is there any other alternative?

Takis_12:12:42

i need just small js file

Takis_12:12:19

is it possible to send me that temp project you made ? to see the src ?

Takis_12:12:32

i never used shadow-cljs

Takis_12:12:54

or a link of how to use shadow-cljs

p-himik12:12:52

This is the full source code:

(ns clj-playground.single)

(js/console.log (let [acc #js []]
                  (loop [i 10]
                    (when (pos? i)
                      (.push acc i)
                      (recur (dec i))))
                  acc))
And this is the whole config file:
{:source-paths ["src"]
 :builds       {:single {:target           :browser
                         :output-dir       "public/js/compiled-single"
                         :compiler-options {:output-feature-set :es6}
                         :js-options       {:babel-preset-config {:modules "commonjs"
                                                                  :targets "chrome > 70"}}
                         :modules          {:main
                                            {:entries [clj-playground.single]}}}}}

p-himik12:12:18

I ran it as shadow-cljs release single and got a single 286 character JS file.

Takis_12:12:43

great thank you alot,its important for me 🙂

p-himik12:12:35

If you decide to stick with it, be sure to read the shadow-cljs documentation and play around with :compiler-options and :js-options.

Takis_12:12:01

yes i will read those now 🙂 have a nice day

Takis_14:12:03

thank you clyfe i will check it now, seems that i can complile differently to produce much smaller javascript code,i am trying shadow-cljs

jmckitrick21:12:09

I have a legacy project using the old (original) figwheel. I have it working with CIDER, but I always run (stop-autobuilds) and then (start-autobuilds) to add my ‘test’ build id. Is there a way to make that happen automatically? Again, this is the old figwheel, not figwheel-main….