I downloaded the fulcro template to play around with, but I'm getting an net::ERR_CONNECTION_REFUSED
whenever I start the server. Has anyone encountered this error before with shadow-cljs?
I ask here because the terminal spat out an error that pointed to some shadow-cljs code.
The namespace is shadow.cljs.devtools.client.websocket
line 12. Still looking into it though. It seems like anything could cause this which is worrisome.
looking at some of the issues in the github, something with websocket I guess.
redownloading the template caused it to go away. I have no idea why.
Is there any way I can inline the compiled output into the HTML file? Something like HtmlWebpackInlineSourcePlugin but for shadow-cljs
another question, is there a target for generalized JS environment? The context I'm trying to run in is not a browser environment (no access to browser APIs) nor nodejs (so can't use dirname and other nodejs specific things). The environment is a sandboxed browser environment with ES6, with removed browser APIs
more questions, slightly related. There is bunch of extra (undocumented) targets in https://github.com/thheller/shadow-cljs/tree/b05b8f41afd45564ef7b9831a07201d09a5c4a07/src/main/shadow/build/targets, can I use them from the shadow-cljs npm module somehow? I'm not able to figure out how...
@victorbjelkholm429 there is nothing to do the inline the output into html. you could just to it in an extra step after compilation thought. need more information before I can comment on the target thing. Maybe :target :esm
does what you need in release
mode or any of the node stuff. just don't expect watch
or compile
to work. release
output might work.
Managed to get it to work by using a combination of compile
for the "Figma UI target" and release
for the "Figma background target", and using the :browser
target for both. Thanks for the help!
the :ui-dev
build you do not need
https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration
or I guess the :ui
build is old since its still :npm-module
?
@thheller I do π I have two different environments, one where I simulate the Figma environment in the browser
has to be a npm module as after shadow-cljs I pass it to webpack to inline UI into the index.html (needed for Figma...)
it's a bit tricky and messy, but it works at least. Basically I shim the APIs that Figma provide in the plugin context, if FIGMA is false. So I can develop most of it in browser, and then only test integration in figma itself
well there could be a :target :figma-plugin
or so that takes care of some of the messiness
but I don't have time to look into that currently
@thheller don't worry about it, thanks for the guiding so far. I think it's a pretty small intersection of people who write clojure and writes Figma plugins π I might open source the wrapper I'm using, to help others, and if that sees any interest, I could think about contributing a :figma-plugin
target
https://clojureverse.org/t/generating-es-modules-browser-deno/6116
Interesting, I'll take a look at the :esm target, thanks! For now, watch/compile for that is not super important, can work around that for now.
for the record, here is where I'm trying to get it to run: https://www.figma.com/plugin-docs/how-plugins-run/
Basically has two different contexts. One "UI" that has access to all the browser APIs but cannot load JS sources via script tags, everything has to be inlined.
The other one "code" (basically background) that has no access to browser APIs but custom ones like the figma
one.
Currently I got the UI one working fine by having shadow-cljs output a npm-module that I'm including in a "vanilla JS" file, then webpack packs it + index.html into a single file with the JS embedded.
Having harder time getting the "code" context to work, as output from shadow-cljs (cljs-compiler maybe?) is either assuming it's in a browser OR nodejs context while in "code" context, neither global
, process
nor window
is available
:target :browser
may work too, but again just in release
in compile
or watch
it will definitely try to access all of those
Hm, I'll give release
a try, didn't try it before with the :browser
target. Thanks for the guidance!
Is there a way to make React Native hot reload feature work? Somehow Metro bundler reloads the whole bundle after recompilation
disable it completely and let shadow-cljs handle the reload
https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html
check the "things to avoid" and "hooking up react"
I think I finally made it work, thanks a lot for your help!
otherwise no clue
Hi. I have a CommonJS module in src/add.js
(`module.exports = add`) and this CLJS code in src/habit/core.cljs
:
(ns habit.core
(:require [moment]
["/add" :as add]
))
(println (add 1 2))
(defn main []
(println "hi"))
With this shadow-cljs.edn
:
{:source-paths
["src/"]
:dependencies
[]
:builds
{:m
{:target :node-script
:main habit.core/main
:output-to "out/core.js"
}}}
I then run sc cljs-repl m
and node out/core.js
which outputs "3" and "hi". However, in the repl, I get this error when trying to access add
: #object[ReferenceError ReferenceError: module$add is not defined]
. I can access moment fine. What am I doing wrong?@lightningstrikeiv which version?
2.11.4
@thheller thanks for the pointer! It works much better (the currently active screen doesnβt refresh though)
Should I try an earlier one?
no. just ruling out that you are on old versions π
might just be a bug in the node-repl. don't really know. not something alot of people do
you must set up the re-rendering properly
so if nothing refreshes you likely have done something that breaks that or not done it at all
you can use the helper I added for this https://github.com/thheller/reagent-react-native/blob/master/src/main/test/app.cljs#L36
got it, thank you!