简体   繁体   中英

How can I deploy a Reagent application, without needing Figwheel?

I wrote a web application in Reagent, and I develop and run it locally using Figwheel, which is great. Now I want to deploy it, so I ran "lein ring uberwar". It says "Compiling ClojureScript..." (3 times!), which sounds promising. But then when I deploy the war file and visit the page, I get a flash of:

ClojureScript has not been compiled!
please run lein figwheel in order to start the compiler

before the application kicks in.

Should Figwheel even be involved in production deploys? Can I build an uberwar that doesn't have this FOUC-like flash?

I found How do I deploy a single-page app. written in ClojureScript / Figwheel to a static server? but it seems to start from scratch (not Reagent-specific), and a lot of the links are dead.

I'm not familiar with how figwheel/uberwar work so I don't even know what to try.

This happens even with a plain 0.8.1 Reagent project, AFAICT.

I see a Figwheel warning text very briefly, when I first visit the page. I'd like to see nothing at all, until the page loads. (Or maybe let me put in a custom spinner or something, but one thing at a time.) I'd also like to not have to package and send unnecessary Figwheel code to every client, because it's not big but it should never be needed there.

I think you are looking for lein uberjar :

~/expr/cljs-enflame > lein uberjar
Created /home/alan/expr/cljs-enflame/target/cljs-enflame-0.1.0-SNAPSHOT.jar
Created /home/alan/expr/cljs-enflame/target/cljs-enflame-0.1.0-SNAPSHOT-standalone.jar

You can then deploy the standalone version, and kick off your program with a command like:

> java -jar target/cljs-enflame-0.1.0-SNAPSHOT-standalone.jar

where you specify the main program entry point in project.clj like:

:main  demo.hello

I think your packaging process will require two steps:

  • First: Compile the ClojureScript code with a production profile. You probably have something like that available with lein cljsbuild prod once or a similar target. The idea is that you want the production profile to produce that single, optimized JavaScript file that will be served by Tomcat as a static resource.

  • Second: build the WAR file for Tomcat, with lein ring uberwar .

Depending on how you serve static files from your web application, the path to the static resources may change, but unless you add any other configuration, you'll be either serving the static resources as explained in this answer: https://stackoverflow.com/a/7820392/483566

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM