Fork me on GitHub
#reagent
<
2020-06-12
>
EmmanuelOga09:06:38

Sup! I want to just render two spans inside some container: (rdom/render [:div.wrapper [:span "Hello"] [:span "world"]] some-dom-elem). This works allright, but what if I want to remove the :div.wrapper? Can't seem to find a way to render a list of elems without a root element. This is annoying because my html ends up using an unneeded wrapper: <div id="wrapper"><div class="wrapper"><span... etc

EmmanuelOga09:06:17

Oh, that was easy, I just replace :div with :<> . Perfect, thx!

Daniel Hutzley22:06:31

Hey, I am having some trouble building a release binary. From a fresh install of the template, how would I build a html webpage that I can move onto a server and use?

noisesmith22:06:01

@endergeryt if it's a lein template, use lein uberjar to create a fat jar, the resulting jar (there's two, you want the one with "standalone" in the name) can be run via java -jar ...

Daniel Hutzley22:06:24

When I run the uberjar, it drops me into a clojure REPL

noisesmith22:06:05

oh - it must be avoiding aot

Daniel Hutzley22:06:31

How would I prevent that?

noisesmith22:06:41

try java -jar my-standalone.jar -m my.ns

noisesmith22:06:24

you don't need aot, it just means your startup is slightly more verbose a command line

Daniel Hutzley22:06:04

whenever I do that, it appears to only be looking for clojure and cljc files, but not cljs files

Daniel Hutzley22:06:24

I should note that I'm using the frontend template

noisesmith22:06:41

to run cljs files, you need to connect to the clj server

noisesmith22:06:59

perhaps you want electron rather than reagent if what you want is an app?

Daniel Hutzley22:06:49

It's a website, I just used the frontend template. How would I get the clj server running? It works with figwheel

noisesmith22:06:49

running the main ns created by the template (named based on your creation args) will by default start a web server that serves html providing your reagent cljs app

noisesmith22:06:06

figwheel is a dev only tool and shouldn't be used in production

Daniel Hutzley22:06:00

ok, where would the main namespace be located in my sources?

noisesmith22:06:50

if you created it via lein new reagent foo it would be in src/foo/core.clj if you used lein new reagent org.foo/bar it would be in src/org/foo/bar.clj

Daniel Hutzley22:06:41

Hm, is there a way to move from the reagent-frontend template to the plain reagent template easily?

noisesmith22:06:28

oh! I missed that you were using the separate reagent-frontend package, sorry

noisesmith22:06:53

if you use lein new, there should be very few files to copy over from the other project, that's likely the easiest thing

Daniel Hutzley22:06:16

Ok, I'll try to create a reagent standard template and transplant the files

noisesmith22:06:04

I think the main thing is that src/foo.cljs in reagent-frontend becomes src/cljs/foo.cljs in reagent

Daniel Hutzley22:06:47

How would I get it to not use the router

noisesmith22:06:15

why would you need it to do that?

Daniel Hutzley22:06:45

The way the site is constructed is that it uses an atom to control where it is on the site

Daniel Hutzley22:06:59

Unless the router can modify the atom

noisesmith22:06:10

sounds like you just want a single page

Daniel Hutzley22:06:22

yeah, that's how I set it up

noisesmith22:06:52

easiest thing is to use only one route in the router

noisesmith22:06:18

you can run without a router, but that's definitely not the easy thing to do

noisesmith22:06:15

even with a SPA you usually end up with routes for serving data queries

noisesmith22:06:21

anyway, now that I think for a moment longer, the router implements a function, you can just replace it with any other function from request -> response (eg. your page handler), or just have no routes defined and serve everything via static resources (but at that point why even use clojure on the back end, maybe you'd want nginx instead...)

Daniel Hutzley22:06:04

how do I get it to serve cljs instead of the hiccup?

noisesmith22:06:09

the original project should have had an http template that pulled in the js from your cljs, and rendered the hiccup

Daniel Hutzley23:06:56

how would I configure somethiing to just serve it, since I just need it set up as a single page webapp. I just cannot figure out how to compile the frontend into something I can render

lilactown23:06:39

@endergeryt it looks like the reagent-frontend project has a command to bundle up all of your JS

Daniel Hutzley23:06:49

Ok, what would that be?

lilactown23:06:54

in the README

lilactown23:06:18

> Building for production

lein clean
 lein package

lilactown23:06:38

that will build a production JS bundle, which you can then upload to a file hosting service

noisesmith23:06:11

oh wow, I really was sending this on a wild goose chase, sorry

Daniel Hutzley23:06:28

It's fine, honestly I probably wasn't helping the situation much. Thanks for the help!

Daniel Hutzley23:06:48

What do I do about the stuff in the index.html file? Do I include that too?

lilactown23:06:31

yeah, you can upload that as well if it matches what you want in production

Daniel Hutzley23:06:43

Um, slight problem. Whenever I try and run the index.html file in the browser, I get the ClojureScript has not been compiled div instead of the real app

lilactown23:06:09

could be a number of issues. is your JS bundle being loaded?

Daniel Hutzley23:06:54

how can I check if that is the case? The script tag is there

Daniel Hutzley23:06:53

I think it's a problem of it trying to run from the root of my filesystem, how do I avoid that

Daniel Hutzley23:06:40

Yeah, it's just my links trying to go from the root of my filesystem

lilactown23:06:08

it would say in the console or network tab if the script failed to load

Daniel Hutzley23:06:01

Yeah, I've figured out the issue. I got it working. Thanks though!