shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Mr. Savy 2020-10-04T00:06:53.257Z

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.

Mr. Savy 2020-10-04T00:09:15.257100Z

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.

Mr. Savy 2020-10-04T00:59:30.257300Z

looking at some of the issues in the github, something with websocket I guess.

Mr. Savy 2020-10-04T04:35:12.257500Z

redownloading the template caused it to go away. I have no idea why.

victorb 2020-10-04T10:38:59.258100Z

Is there any way I can inline the compiled output into the HTML file? Something like HtmlWebpackInlineSourcePlugin but for shadow-cljs

victorb 2020-10-04T10:51:44.258900Z

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

victorb 2020-10-04T11:21:28.259700Z

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...

thheller 2020-10-04T13:26:26.261600Z

@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.

victorb 2020-10-05T09:02:14.289900Z

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!

thheller 2020-10-05T09:03:52.290400Z

the :ui-dev build you do not need

thheller 2020-10-05T09:05:07.291900Z

or I guess the :ui build is old since its still :npm-module?

victorb 2020-10-05T09:05:12.292100Z

@thheller I do πŸ™‚ I have two different environments, one where I simulate the Figma environment in the browser

victorb 2020-10-05T09:05:40.292500Z

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...)

victorb 2020-10-05T09:06:50.292700Z

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

thheller 2020-10-05T09:12:08.293Z

well there could be a :target :figma-plugin or so that takes care of some of the messiness

thheller 2020-10-05T09:12:15.293200Z

but I don't have time to look into that currently

victorb 2020-10-05T09:23:13.293400Z

@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

thheller 2020-10-04T13:27:01.261800Z

https://clojureverse.org/t/generating-es-modules-browser-deno/6116

πŸ™ 1
victorb 2020-10-04T13:30:09.262Z

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.

victorb 2020-10-04T13:33:20.262200Z

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

thheller 2020-10-04T13:35:19.262500Z

:target :browser may work too, but again just in release

thheller 2020-10-04T13:35:30.262700Z

in compile or watch it will definitely try to access all of those

victorb 2020-10-04T13:35:48.262900Z

Hm, I'll give release a try, didn't try it before with the :browser target. Thanks for the guidance!

xfyre 2020-10-04T21:44:39.264300Z

Is there a way to make React Native hot reload feature work? Somehow Metro bundler reloads the whole bundle after recompilation

thheller 2020-10-04T22:02:07.265200Z

disable it completely and let shadow-cljs handle the reload

thheller 2020-10-05T08:57:34.287300Z

check the "things to avoid" and "hooking up react"

xfyre 2020-10-05T16:48:26.295200Z

I think I finally made it work, thanks a lot for your help!

thheller 2020-10-04T22:02:11.265400Z

otherwise no clue

Galagora 2020-10-04T22:11:20.269300Z

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?

thheller 2020-10-04T22:22:06.269800Z

@lightningstrikeiv which version?

Galagora 2020-10-04T22:23:37.270Z

2.11.4

xfyre 2020-10-04T22:26:24.270300Z

@thheller thanks for the pointer! It works much better (the currently active screen doesn’t refresh though)

Galagora 2020-10-04T22:27:16.270500Z

Should I try an earlier one?

Galagora 2020-10-04T22:31:34.270700Z

@thheller

thheller 2020-10-04T22:33:45.270900Z

no. just ruling out that you are on old versions πŸ˜›

thheller 2020-10-04T22:34:24.271100Z

might just be a bug in the node-repl. don't really know. not something alot of people do

thheller 2020-10-04T22:35:21.271300Z

you must set up the re-rendering properly

thheller 2020-10-04T22:35:40.271500Z

so if nothing refreshes you likely have done something that breaks that or not done it at all

thheller 2020-10-04T22:35:56.271700Z

you can use the helper I added for this https://github.com/thheller/reagent-react-native/blob/master/src/main/test/app.cljs#L36

xfyre 2020-10-04T22:37:18.272Z

got it, thank you!