Fork me on GitHub
#figwheel-main
<
2018-09-16
>
bhauman00:09:31

@kwladyka I haven’t tried it with figwheel-main but you can usually add a non local directory to :watch-dirs Example :watch-dirs ["src" "../form-validator-cljs/src"]

kwladyka00:09:41

Directory can’t be outside root directory

kwladyka00:09:19

I am going sleep, but I will read your answer tomorrow. Goodnight :)

bhauman00:09:43

I should fix that

kenran_10:09:41

I have recently started using clojure and cljs and tried out figwheel-main after finding out about it. It feels great! Now I want to deploy my app to a server and I'm failing to create an uberjar containing the "target" dir contents.

kenran_10:09:36

It might be because I'm new to the whole thing and not figwheel-main specific, but I feel like I may be overlooking something in figwheel-main that could help me do this.

kenran_10:09:56

So far I've tried adding in cljsbuild and running that before creating an uberjar (it still doesn't work), but is that even the right path?

kenran_11:09:37

I'm sorry, I got it to work! I forgot to add a resource route. When using lein fig:build, everything works magically for a newbie like me and it seems I have to learn the rest the hard way 🙂

bhauman14:09:21

@johb.maier yeah there needs to be a guide on figwheel that shows specifically how to do this and as you discovered its easiest with lein

bhauman14:09:35

but it really depends on how you are deploying

bhauman14:09:03

as you don’t have to have a jar, you could just be deploying compiled assets somewhere

kenran_18:09:42

@bhauman I ended up adding cljsbuild to my project.clj which then compiles the js output to resources/public/cljs-out. But then I have to gitignore this subdir and I'd love to know how to be able to just package the compiled js that figwheel creates in the target dir into my jar so that it can then be used with that. Is there a way to do this?

bhauman18:09:14

@johb.maier you need to add target to your :resource-paths so that its contents get added to the uberjar

bhauman18:09:49

you can also make a prod.cljs.edn {:main example.core :optimizations :advanced :output-to "resources/public/cljs-out/dev-main.js"}

bhauman18:09:03

and do build once on it

bhauman18:09:18

clj -m figwheel.main -bo prod

kenran_18:09:24

Oh that sounds great! I'll give it a shot tomorrow 🙂

kenran_18:09:03

@bhauman Also thanks for creating this amazing tool! I come from a desktop application, windows and OO only background with an aversion to web development and with figwheel it's just, well, fun!

kenran_18:09:53

Made it easy for me to just jump right in and have a great workflow.

bhauman18:09:13

awesome! really good to hear 🙂

kenran_18:09:07

Made me rent a small vps 😉

👍 4
bhauman18:09:46

I’m really considering switching to a different server in the hopes on not conflicting with jetty

bhauman19:09:11

so very easy to conflict with Jetty

jduhamel19:09:48

Ok, I got a quick sample program up and running with figwheel.main/cider and clj tools. Is there an equivalent to the lein “on-jsload” or do I put it into my dev.cljs.edn? and add a example.core/mount-root

jduhamel19:09:27

Excellent, I hadn’t metadata’d the namespace.

jduhamel19:09:42

@bhauman so it works when I call it manually (refer.app/mount) but it doesn’t seem to be doing the hot-reloading. How can I check what it thinks the hooks are?

bhauman19:09:38

its not calling your reload hook on hot reload?

jduhamel19:09:51

it isn’t.

jduhamel19:09:04

it’s also not calling the export function.

bhauman19:09:05

did you put a console log in the hook?

bhauman19:09:33

what does export function mean?

jduhamel19:09:03

I was going by this example

;; this is what you call for the first mount
(defn ^:export mount []
  (r/render [my-main-component]
            (js/document.getElementById "app")))
  
;; and this is what figwheel calls after each save
(defn ^:after-load re-render []
  (mount))

jduhamel19:09:13

so I added.

(ns ^:figwheel-hooks refer.app
  (:require
   [reagent.core :as reagent]
   [re-frame.core :as re-frame]
   [refer.events :as events]
   [refer.views :as views]
   [refer.config :as config]))

;; Setup config paramaters.
(defn dev-setup []
  (when config/debug?
    (enable-console-print!)
    (println "dev mode")))

;; Grab the base component and render it.
(defn mount-root []
  (.log js/console "Starting App")
  (re-frame/clear-subscription-cache!)
  (reagent/render [views/main-panel]
                  (.getElementById js/document "app")))

;; Starting / Entry point for the app.
(defn ^:export init []
  (.log js/console "Starting init")
  (re-frame/dispatch-sync [::events/initialize-db])
  (dev-setup)
  (mount-root))

(defn ^:after-load re-render[]
  reagent/render [views/main-panel] (.getElementByIdjs/document "app"))

jduhamel19:09:42

when I call (refer.app/init) from the repl it works fine.

bhauman19:09:42

there’s a missing paren there?

jduhamel19:09:43

Sorry that was a testing artifact.

jduhamel19:09:08

fixed it same thing. is there a way to see what figwheel-main thinks the ^:export and ^:after-load is?

bhauman19:09:38

figwheel doesn’t call the ^:export function

bhauman19:09:55

you would need to do that explicitly

bhauman19:09:23

I’m sorry if the docs imply that

bhauman19:09:47

^:export is part of ClojureScript

bhauman19:09:11

that allows you to call it from outside of Clojurescript

jduhamel19:09:13

right, I added that to the javascript call in index.html

jduhamel19:09:33

so it just calls the after-load on reloads.

bhauman19:09:41

oh so its working

bhauman19:09:22

OK in the dev console you should be able to find your init function

bhauman19:09:50

by typing your clojurescript namespace and letting autocomplete guide you

bhauman19:09:03

you may be calling it wrong

jduhamel19:09:29

it works perfectly in the repl.

bhauman19:09:51

you need to make sure that the javascript call is working right?

bhauman19:09:12

and just to be clear this isn’t related to figwheel

bhauman19:09:01

but the console should complain if the call on your html page isn’t able to call the init fn

bhauman19:09:21

but there could theoretically be a race condition

bhauman19:09:35

and the init function may not be available

bhauman19:09:15

@jduhamel for now just put your init call in a defonce

bhauman19:09:28

and eliminate that as a cause

bhauman19:09:36

I think you are experiencing a race condition

bhauman19:09:46

where init isn’t available when you call it

zane18:09:43

I had this happen once, which was surprising to me because my call to init was in a window.onload callback. Does anyone have a sense of what can cause this to happen / what can be done to prevent it?

jduhamel19:09:56

ah that makes sense. Thanks for the help. Been spending a couple of days moving from Lein to clj and ti’s bene making me understand all the internal plumbing more than I ever have.

bhauman19:09:34

So that’s a bad example in the docs

bhauman19:09:42

I’m going to update it

jduhamel19:09:30

Actually, I found your figwheel-main tutorial really helpful.

jduhamel20:09:51

Dropping it into a defonce made it all work. The tutorial waas great in that it really helped see where the plumbing in clojurescript was and also how to get the repl working.

jduhamel20:09:10

The only think that was missing is a simplifed deps.edn and build to use it with the clojure command line tools.

zane18:09:43

I had this happen once, which was surprising to me because my call to init was in a window.onload callback. Does anyone have a sense of what can cause this to happen / what can be done to prevent it?