Fork me on GitHub
#shadow-cljs
<
2018-04-27
>
cjmurphy02:04:04

@thheller I use a tool with cljs-shadow that requires an entry in [:devtools :preloads]. This tool reads from its own .edn configuration file. The same tool works with Figwheel and the instruction was to (reload-config) after making changes to the configuration file. Is there an equivalent command for cljs-shadow? What worked for me was to rm -rf the builds directory.

zarkone07:04:19

hi, I have another dumb question about cljc! so, I've defined a few lines in .cljc file:

#?(:node-script (.log js/console (str "HAHAHAHA.1")))
#?(:browser (.log js/console (str "HAHAHAHA.2")))
#?(:cljs (.log js/console (str "HAHAHAHA.3")))
and I also have this in build conf:
:reader-features #{:node-script}
:target :node-script
but I get only :cljs branch compiled, for some reason. Tried to use :node instead, same result

thheller08:04:58

@cjmurphy which tool is that?

thheller08:04:37

@zarkone :compiler-options {:reader-features #{:node-script}}

zarkone08:04:52

@thheller sorry, this one also was obvious >..< But now I better understand how it works. Thank you!

thheller08:04:01

I'll probably add a section about it in the docs. It is a useful feature after all.

zarkone08:04:10

yes, it is, definitely! Currently porting our SPA app to SSR, quite tough task, but I think it would be impossible at all without complete rewriting without this conditional features

thheller08:04:01

yeah thats what I used it for too. although I abandoned the SSR idea half way through. couldn't live with having to do JS on the server 😉

zarkone08:04:33

yes, but I just don't know any other solution in my case: we have SPA app and now "it turns out" that we need SEO to actually be crawler-friendly and etc

zarkone08:04:30

either completely different codebase, doing html version for crawlers or something like this.

thheller08:04:15

SEO with just plain SPA can work but it seems to take google longer to index this and doesn't work at if you send out too many requests and such

thheller08:04:26

+ bing and others definitely don't index SPAs properly

thheller08:04:34

so yeah HTML is probably the safest option

zarkone08:04:45

yes, so decided at least give this nodejs react server renderer a try, if not -- will have to rollback to this second idea

thheller08:04:11

https://searchengineland.com/tested-googlebot-crawls-javascript-heres-learned-220157 I replicated their results basically with one exception in 3. Google never recognized dynamically generated JSON-LD metadata

thheller08:04:00

but definitely try the node server renderer and blog about your experience

thheller08:04:08

maybe you have more patience than I did 😉

zarkone08:04:08

haha) you suggest to add yet another tutorial article about server-side rendering to feed trolls? 🙂 ok, sounds nice -- at least, I haven't seen the one with shadow-cljs, AFAIR

thheller08:04:52

hehe 😉

troglotit08:04:19

What is the correct way specify shadow-cljs version in package.json and shadow-cljs.edn? Should they match 100% time or is it redundant to have it in shadow-cljs.edn

thheller08:04:52

not required in shadow-cljs.edn at all. it will pick whatever version is installed by npm so only package.json matters.

thheller08:04:40

don't need to specify a clojurescript or clojure version either.

zarkone09:04:44

Looks great in my opinion! All the problems I've faced so far were touched. Thank you! :)

cjmurphy10:04:04

@thheller Its a tool I use with Fulcro that catches anytime the state becomes de-normalized: https://github.com/chrismurrph/default-db-format. Currently it is written mainly assuming users use Figwheel.

thheller10:04:39

you'll probably need to add the default-db-format.prefs since that does a side-effecting read of the config file

thheller10:04:36

deleting all the cache is kind of a nuclear option and not really required. since its only about that one single thing.

simple_smile 4
j11:04:14

hey @thheller im trying to compile a node-script as such

//shadow-cljs.edn
{:builds {...
   :target :node-script}}

$ shadow-cljs release <script-id>
and based on the documentation it's supposed to output some single-file stand-alone script. But when I take it out of the directory it was built and put it inside a new dir, it won't run. I've tried to debug the problem and it seems that use the nodejs require as such:
shadow.js.shim.module$react_dom$server=require("react-dom/server")
So I then figured that maybe I can use the :js-options :shadow and I did but now I'm stuck because while it works on the watch mode it will fail on release. I'm running it likeso:
$ shadow-cljs release <script-id> --debug

IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword
	clojure.lang.RT.seqFrom (RT.java:550)
	clojure.lang.RT.seq (RT.java:530)
	clojure.lang.APersistentMap.cons (APersistentMap.java:40)
	clojure.lang.RT.conj (RT.java:670)
	clojure.core/conj--5112 (core.clj:85)
	clojure.core/merge/fn--5679 (core.clj:3041)
	clojure.core/reduce1 (core.clj:936)
	clojure.core/reduce1 (core.clj:926)
And I have no idea how to debug from this 😞

thheller11:04:45

@j it outputs a single file yes. it however still requires the node_modules files since node will load these. so if you move the file you need to move it together with the package.json and install the deps in a new location.

thheller11:04:28

it is not currently supported to bundle all deps since that would significantly reduce the number of packages you'd be able to use (ie. nothing with native deps)

thheller11:04:25

:js-provider :shadow can work in theory but I never tested it in combination with :node-script

thheller11:04:43

"stand-alone" in the docs mean that shadow-cljs is not required after the file is compiled. it does not mean that node_modules will be bundled.

thheller11:04:59

I can take a look at making :js-provider :shadow work with :node-script later but as I said this severly limits the number of packages you'll be able to use.

thheller11:04:50

I will clarify this in the docs.

j11:04:12

Thanks for the quick reply, and it seems that the quick solution is just to include a package.json. Either way, great work on this tool! 🙂

thheller11:04:28

yep that is best

thheller11:04:29

I typically create an extra :output-to "out/foo.js" directory with a dedicated out/package.json file that only contains stuff actually required to run the script. eg. no devDependencies.

davidw13:04:16

am I right in thinking using the path to a jsfile within an npm package in the require e.g.

(ns foo.core
  (:require ["jsonld/dist/jsonld.js" :as jsonld]))
and using :js-options :resolve to redirect the require e.g.
:js-options {:resolve {"jsonld" {:target :npm
                                  :require "jsonld/dist/jsonld.js"}}}
(ns foo.core
  (:require ["jsonld" :as jsonld]))
should be equivalent?

steveb8n13:04:40

hi everyone. I’ve made significant progress on Stu this week. check out the latest. https://github.com/stevebuik/Stu

steveb8n13:04:21

tomorrow I will deploy to clojars and log issues so anyone willing to help know where to start

steveb8n13:04:29

I’d appreciate any feedback

thheller16:04:55

love the pre-closure toggle. the switch for compressed however is a bit useless since everything should always be zipped the the other number is a bit irrelevant. unlikely you gzip one release but not the other.

thheller16:04:13

still not a super fan of the tree-map display. hard to make out any actually useful info.

thheller16:04:19

definitely need to trim some deps for shadow-cljs 😉

steveb8n22:04:37

@thheller Good to know. Are you able to state the questions that you are trying to answer? That will enable me to know what new features you and others would find valuable

colindresj16:04:51

I followed the guides for :target :karma, and the shadow-cljs build goes through fine, but when doing karma start I’m getting a reference error require is not defined

colindresj16:04:43

Running on shadow-cljs 2.3.10 and configs look like this:

thheller16:04:27

@colindresj require is not defined where? any chance your code has a js/require call somewhere?

thheller16:04:27

@davidw yes that is equivalent when using :target :browser

colindresj16:04:19

@thheller in my output file (`test-ci.js`). Line looks like this: shadow.js.shim.module$react = require("react");

thheller16:04:12

oh the extra resolve toggled something off

thheller16:04:30

js-options isn't getting merged it is replaced

colindresj16:04:41

Ah, I was thinking it had something to do with that

thheller16:04:50

oops. you can temp fix it by adding :js-options {:js-provider :shadow :resolve ...}

thheller16:04:57

will fix that in next release

colindresj16:04:59

Cool, will do

colindresj16:04:06

As an aside, I thought shadow was the default provider @thheller

colindresj16:04:10

Is it target specific?

colindresj16:04:27

Actually that makes sense — for node is probably require, etc

thheller16:04:55

yeah :shadow is only the default for the :browser, otherwise :require

sveri18:04:51

Hi, I have a dependency that requires the jquery cljsjs package. So I added th jquery.cljs file in the cljsjs package like this:

(ns cljsjs.jquery
  (:require ["jquery" :as jquery]
                 ["$" :as jq]))

(js/goog.object.set jquery "$" jq)
(js/goog.exportSymbol "jquery" jquery)
The first error: The required namespace "cljsjs.jquery" is not available, it was required by "re_pressed/impl.cljs". is gone, but now it complains about $: `The required JS dependency "$" is not available, it was required by "cljsjs/jquery.cljs". Any idea how to reference that? My code above does not work.

sveri18:04:22

Thanks to @gadfly361 I have this working now:

🍻 4
sveri18:04:30

(ns cljsjs.jquery
  (:require ["jquery" :as jquery]))

(js/goog.exportSymbol "jQuery" jquery)

davidw18:04:12

@thheller good to know about the reported issue. We ran into that and are working around it by using the jsonld/dist/jsonld.js require redirect but that wasn't working with our :target :karma build where we got require is not defined errors running the tests. It worked when I put the path in the require directly which seemed strange, hence the question. So it looks like we were running into the same issue as @colindresj

thheller18:04:44

@davidw yeah thats my bad. should be fixed in the 2.3.11 release I just pushed. or just add :js-provider :shadow to your :js-options.

thheller19:04:28

@sveri $ is only the variable, it is not an npm package. you can just add the additional (js/goog.exportSymbol "$" jquery) if you like

sveri19:04:32

@thheller I got it working without the $ line. I already added a PR: https://github.com/thheller/shadow-cljsjs/pull/6 Thanks for putting all that together.

thheller19:04:57

ah excellent. thx.

sveri19:04:29

@thheller thanks for the instant release, I just included the updated version and it works, awesome. Do you have a automatic build set up?

thheller19:04:06

not really. but its just lein deploy clojars so pretty quick to do.