figwheel-main

figwheel-main http://figwheel.org
Adriaan Callaerts 2020-09-28T11:56:36.001500Z

Hi everyone, I'm trying to find examples of how to set up a production build for a project that combines a clj backend with a cljs frontend. Any pointers?

athomasoriginal 2020-09-29T13:02:47.014Z

deadghost is right that it’s not entirely related to figwheel (figwheel is involved a bit), but those other tools wouldn’t really help and if you’re using figwheel already aren’t needed.

Adriaan Callaerts 2020-10-01T13:31:02.025200Z

My more specific problem is actually the following: the examples/documentation I can find suggests doing a production build by running lein run -m figwheel.main -O advanced -bo prod as a prep-task of lein uberjar. However, in order for that to work, figwheel-main has to be in the list of "main" dependencies of my project (as opposed to only the dev dependencies). As a consequence of that, classes and assets of figwheel-main (including auto-test and devcards-related stuff) get inserted into my uberjar, which is not what I want.

athomasoriginal 2020-10-01T14:14:02.025900Z

Cool. Thanks for the clarification 🙂 I’m not sure the article your referring to, but what you would need to do is 1. build a production bundle of your JS 2. build your Uberjar I’m assuming the article is stating that your uberjar will have the production bundle of JS you built in step 1 included. If I had to guess, this would mean it gets moved into resources/public (or wherever it gets served from) when it’s built in step 1. Going over this, you shouldn’t need to add figwheel as a “main” dependency. figwheel.main is just a library. So, you can call it in anyway you see fit. The result of calling it is it will find your JS, advance compile it, and output the compilation wherever you specify.

athomasoriginal 2020-10-01T14:16:45.026100Z

So, you could just create any other lein command that runs figwheel.

deadghost 2020-09-28T13:59:08.001600Z

That's probably not figwheel specific. You'd want to look for cljsbuild or shadow-cljs configs depending on which you're using.

deadghost 2020-09-28T14:20:23.006300Z

lein trampoline run -m figwheel.main -- -b dev -r
Anyone know what the -- is for?

athomasoriginal 2020-09-29T13:10:57.014300Z

It’s usually used to tell the CLI when to stop parsing options and in this case, the next set of options are going to be passed in a different way

athomasoriginal 2020-09-29T13:11:55.014500Z

This pattern is seen in the clj/clojure tool as well. For example, if you type clj -h you will see at the end of the dep-opts section there is a description of --

--             Stop parsing dep options and pass remaining arguments to clojure.main 

1👍
thelittlesipper 2020-09-28T14:37:07.011700Z

Hey all! I’m trying to migrate our web-app to use :target :bundle , and we’ve gotten to the point where the app works fine, but running the CLJS tests in the CLI causes https://github.com/bhauman/figwheel-main/issues/159 with the following log output: [0928/100959.043338:INFO:<http://headless_shell.cc|headless_shell.cc>(448)] Type a Javascript expression to evaluate or "quit" to exit. The CLJS CLI tests were running just fine before the migration to :target :bundle. test.cljs.edn before changing to :target :bundle:

^{:log-file  "log/figwheel-main.log"
  :log-level :info
  :launch-js ""scripts/headless-chrome""
  :open-url  "<http://localhost:9500>"
  :npm       {:bundles {"dist/index.bundle.js" "src/js/index.js"}}}
{:main            my-app.test-runner
 :optimizations   :none
 :closure-defines {"re_frame.trace.trace_enabled_QMARK_"        true
                   "day8.re_frame.tracing.trace_enabled_QMARK_" true
                   goog.DEBUG                                   true}}
test.cljs.edn after changing to :target :bundle:
^{:launch-js "scripts/headless-chrome"
  :open-url "<http://localhost:9500>"}
{:main            my-app.test-runner
 :optimizations   :none
 :target          :bundle
 :bundle-cmd      {:none    ["yarn" "webpack" "--mode=development"
                             :output-to "-o" "resources/public/cljs-out/main_bundle.js"]}
 :closure-defines {"re_frame.trace.trace_enabled_QMARK_"        true
                   "day8.re_frame.tracing.trace_enabled_QMARK_" true
                   goog.DEBUG true}
Navigating to <http://localhost:9500> while Chrome is hanging shows this page: https://i.gyazo.com/883ebb193ccbc03a07b4eb5d9326c49b.png Dependencies are up to date for CLJS and Figwheel.

thelittlesipper 2020-09-28T14:53:36.012200Z

Fixed! had to add index.html to the open url: :open-url "<http://localhost:9500/index.html>. I don't know why that's required all of a sudden, but :man-shrugging:

deadghost 2020-09-28T16:16:23.013700Z

project.unit.foo=&gt; (rf/reg-sub :test (fn [db _] :hello))
#object[TypeError TypeError: Cannot read property 'call' of undefined]
	 (&lt;NO_SOURCE_FILE&gt;)
	 re-frame.registrar/register-handler (resources/public/js/compiled-test-nodejs/out/re_frame/registrar.cljc:67:3)
	 Function.re_frame.subs.reg_sub.cljs$core$IFn$_invoke$arity$variadic (resources/public/js/compiled-test-nodejs/out/re_frame/subs.cljc:183:6)
	 Function.f (resources/public/js/compiled-test-nodejs/out/re_frame/subs.cljc:149:1)
	 (resources/public/js/compiled-test-nodejs/out/cljs/core.cljs:3895:30)
	 (resources/public/js/compiled-test-nodejs/out/cljs/core.cljs:3887:1)
	 Function.re_frame.core.reg_sub.cljs$core$IFn$_invoke$arity$variadic (resources/public/js/compiled-test-nodejs/out/re_frame/core.cljc:189:4)
	 re_frame$core$reg_sub (resources/public/js/compiled-test-nodejs/out/re_frame/core.cljc:58:1)
Any idea why figwheel-main + lein + nodejs + re-frame doesn't want to cooperate with me?

deadghost 2020-09-28T20:02:31.013800Z

Got it, re-frame bump to 1.1.1 did it.