This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-21
Channels
- # announcements (11)
- # architecture (8)
- # aws (7)
- # babashka (1)
- # beginners (55)
- # calva (52)
- # cider (4)
- # clj-kondo (5)
- # clojure (12)
- # clojure-europe (7)
- # clojure-uk (3)
- # clojurescript (40)
- # clr (1)
- # conjure (5)
- # data-oriented-programming (7)
- # datomic (8)
- # emacs (3)
- # events (1)
- # graphql (2)
- # honeysql (5)
- # lsp (7)
- # missionary (24)
- # nbb (10)
- # off-topic (12)
- # pathom (5)
- # reagent (9)
- # reitit (4)
- # schema (1)
- # sci (9)
- # shadow-cljs (2)
- # specter (6)
- # tools-deps (4)
- # xtdb (13)
When I use :target :bundle
with no optimizations and I load the JavaScript file produced by Webpack I see the browser fail to load the following:
• <asset-path>/goog/base.js
• <asset-path>/goog/deps.js
• <asset-path>/cljs_deps.js
In the browser console I see:
Uncaught ReferenceError: goog is not defined
This appears to be because goog
isn’t available at the top level. In index.js
:
if(typeof goog == "undefined") document.write('<script src="js/goog/base.js"></script>');
document.write('<script src="js/goog/deps.js"></script>');
document.write('<script src="js/cljs_deps.js"></script>');
:optimizations :advanced
seems to work fine. Should :optimizations :none
work, or do I need :optimizations :simple
?What does your config look like? are you using figwheel or shadow?
Neither.
{:main …
:output-to "out/index.js"
:output-dir "out"
:asset-path "js"
:target :bundle
:bundle-cmd {:none ["pnpm" "webpack" "./out/index.js" "-o" "resources/js" "--mode=development"]
:default ["pnpm" "webpack" "./out/index.js" "-o" "resources/js" "--mode=production"]}
:closure-defines {cljs.core/*global* "window"}} ; needed for advanced
https://cljs.github.io/api/compiler-options/optimizations
• :none
- multiple unminified files (fastest for development).
• :whitespace
- single file w/ comments and whitespace removed
• :simple
- single file w/ whitespace optimizations + minified local var names
• :advanced
- single file w/ aggressive renaming, dead code removal, and inlining
But when I don’t set it to anything, per https://clojurescript.org/guides/webpack I get the error above.
advanced
would work because it's going to make a single JS file, but my hunch is the above is a result of asset-path
So, to confirm, are you able to nix the asset-path
and all that other jazz (`output-to` and output-dir
)and just let CLJS output to its default location? From there, I would add back in the custom paths.
Yeah, I imagine :asset-path
isn’t needed because it’s all going to be passed through Webpack anyway, right?
You can add it when you want to customize where your serving your static assets from, but it might be incorrect as you showed above.
indeed. So, where is out
outputting to? target/out
?
in your directory structure. what does it look like?
right, does your web server server out
or resources/public
?
:output-to "resources/js/main.js"
:output-dir "resources/js"
:asset-path "js/"
What about something like the above? I can't remember where CLJS defaults to serving asset though, I thought it was resources/public
Using index.js
instead of main.js
here (`main.js` is what Webpack produces).
:output-to "resources/js/index.js"
It's two level of thinking.
1. Where should the generated code files live? (`output-to` and output-dir
)
2. Where should the content of the generated code look for the modules it depends on? (`asset-path`)
So, output-to
and output-dir
tells the CLJS compiler where you want the code files to live. e.g.
app/
src/
resources/
js/ <-- cljs/webpack puts the code they generate in here
other-cljs-code/
out/base.js
index.js
Then, the code inside of index.js
needs to know where the generated code files live.
<asset-path>/base.js <--- resources/js/
...
I think my misunderstanding was that even in development mode the output of Webpack would still be a completely stand-alone file.
Can somebody tell me why setting a member property in a <canvas> 2d context leads to compilation error like this:
26 | (defn draw [ctx cw ch]
27 | (set! ctx -imageSmoothingEnabled false)
---------^----------------------------------------------------------------------
null
Can't set! local var or non-mutable field at line 27 core.cljs
--------------------------------------------------------------------------------
28 | (doto ctx
29 | (.clearRect 0 0 cw ch)
30 | (.fillRect 0 0 cw ch)
31 | (.drawImage (:cow @images) 40 40)))
relevant code:
(defn draw [ctx cw ch]
(set! ctx -imageSmoothingEnabled false)
(doto ctx
(.clearRect 0 0 cw ch)
(.fillRect 0 0 cw ch)
(.drawImage (:cow @images) 40 40)))
called by component:
(defn canvas []
(let [dimensions (dimensions)
width (:width dimensions)
height (:height dimensions)]
(r/create-class
{:display-name
"app"
:reagent-render
(fn []
[:canvas {:width (:width dimensions)
:height (:height dimensions)
:style {:width "100vw"
:height "100vh"
:display "block"}}])
:component-did-mount
(fn [this]
(let [canvas (rdom/dom-node this)
ctx (.getContext canvas "2d")]
(draw ctx width height)))})))
Ha! They're exactly the same, but there's a bug and that false
is treated as an absence of the value.
Yeah, mentioned it in #cljs-dev and reported at https://ask.clojure.org/index.php/12065/set-a-x-false-doesnt-work-due-to-a-bug