This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-06
Channels
- # babashka (62)
- # beginners (52)
- # calva (37)
- # clj-kondo (23)
- # cljs-dev (13)
- # clojure (18)
- # clojure-europe (7)
- # clojure-sg (1)
- # clojure-spec (27)
- # clojurescript (37)
- # datomic (14)
- # events (2)
- # fulcro (9)
- # graalvm (12)
- # helix (1)
- # introduce-yourself (1)
- # keyboards (3)
- # lsp (3)
- # missionary (24)
- # nextjournal (7)
- # pedestal (3)
- # polylith (15)
- # re-frame (5)
- # reitit (4)
- # releases (2)
- # shadow-cljs (54)
- # testing (7)
- # uncomplicate (4)
Is it possible to use shadow to invoke the google closure compiler with pure JS? The use case is yielding a smaller bundle size by cutting out CLJS since I only use it for small glue code. Say I would have a index.js
instead of src/foobar/main.cljs
, can I configure shadow to use this and bypass CLJS completely?
It's probably a more normal idea to use closure directly, but using shadow makes moving between these approaches less effort
@borkdude shadow can compile JS just fine without any CLJS. instead of :entries [some.cljs.ns]
just use :entries ["/some/files.js"]
:target :esm
sort of doesn't support it though since there is no way to express the exports without namespaced vars 😛
Right now I have this config:
{:deps {:aliases [:dev :demo]}
:dev-http {8002 "public"
8001 "public/test"}
:nrepl {:port 9000}
:builds {:highlighter
{:compiler-options {:output-feature-set :es8}
:target :browser
:output-dir "public"
:modules {:clojure_highlighter {:init-fn clojure-highlighter.main/render}}
:build-hooks [(shadow.cljs.build-report/hook
{:output-to "report.html"})]}}}
note that the js needs to be on the classpath and will be treated as https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js
How to deal with hyphens, do I need to write them as underscores if the dir has underscores?
I tried:
:entries ["clojure_highlighter/main.js"]
:entries ["src/..."]
:entries ["clojure-highlighter/main.js]
but for all of them I get:
The required JS dependency "clojure_highlighter/main.js" is not available.
[:highlighter] Compiling ...
Wrote build report to: /Users/borkdude/Dropbox/dev/blog/report.html
[:highlighter] Build completed. (16 files, 0 compiled, 0 warnings, 2,42s)
0 compiled ;)I tried rollup for tree-shaking, that yielded a bigger bundle size than with Closure + CLJS included ;)
600kb vs 300kb. Doing this pure JS + Closure is going to yield me 200kb instead of 300kb.
don't know.
$ node_modules/.bin/rollup src/clojure_highlighter/main.js -f iife -o public/js/editor.bundle.js -p @rollup/plugin-node-resolve
src/clojure_highlighter/main.js → public/js/editor.bundle.js...
created public/js/editor.bundle.js in 1.1s
$ ls -la public/js/editor.bundle.js
-rw-r--r-- 1 borkdude staff 603547 Nov 6 11:06 public/js/editor.bundle.js
little easier to do in webpack since that has a dedicated dev/production mode similar to shadow
This actually makes me wonder, how do I simply transpile cljs to js?
Like how is it done on http://app.klipse.tech/, where I can do (+ 2 2)
and get ((2) + (2));
?
clojure -A:cljs -M -m cljs.main -re node -r
ClojureScript 1.10.773
cljs.user=> (set! *print-fn-bodies* true)
true
cljs.user=> (defn foo [x] (inc x))
#'cljs.user/foo
cljs.user=> foo
#object[cljs$user$foo "function cljs$user$foo(x){
return (x + (1));
}"]
cljs.user=>
awesomesauce @U11BV7MTK
@c.westrom Hacky way, in a CLJS repl you can do:
cljs.user=> (str (fn [] (+ 1 2 3)))
"function (){\nreturn (((1) + (2)) + (3));\n}"
there is no potential in this at all. please don't use it. this is not suitable to do anything with as one isolated part of JS won't run anywhere without the rest of the runtime 🙂
it's useful to the extent that you can see what the compiler makes of it, but not for anything more than that
Hmmm, was thinking I could use the output if I wanted some dead simple scripts inside a <script>
element in HTML.
If you want something like this you should compile to a single script using optimizations simple or advanced. You can also check out scittle which is an interpreter which allows you to directly include CLJS in script tags.
@thheller ran into a problem with some code I had submitted previously. This fixes it