Fork me on GitHub
#shadow-cljs
<
2019-01-19
>
grav12:01:15

I have a shadow-cljs server running which I’d like to use for both development and release. Can I do something like

BACKEND=localhost npx shadow-cljs start
# from repl: (shadow.cljs.devtools.api/watch :my-app)
# do some development ... then release:
BACKEND= npx shadow-cljs release my-app

grav12:01:42

that is, setting the environment differently for dev and release, given the same server?

grav12:01:53

I know there’s --force-spawn but in my case I have several builds, so reusing the server would be of great benefit

thheller13:01:33

@grav no. that is why I do not recommend using environment variables at all. you can however use the REPL to modify your build config however you want

thheller13:01:35

(defn my-release []
  (-> (api/get-build-config :your-build)
      (assoc-in [:closure-defines '] "foo.bar")
      (api/release* {})))

thheller13:01:44

with api being shadow.cljs.devtools.api

thheller13:01:57

you can run this via shadow-cljs run your.util/my-release

thheller13:01:05

or (your.util/my-release) from the REPL

thheller13:01:35

be careful when using it at the REPL though. this returns the entire build state and will blow up your REPL if it tries to print that since it fairly large

grav13:01:51

@thheller very nice! thank you! 🙂

thheller13:01:47

so just :release {:closure-defines {your.backend/url "foo.bar"}} will take care of everything

grav14:01:40

Ah, that also looks interesting. I need to share the values with the rest of my home-made setup, so I’ll probably be using environment variables (`#shadow/env`) at least for the release part. Or I’ll make the rest of my tooling integrate with the shadow-cljs.edn file and let that be the source of truth

thheller14:01:06

the most flexible is just using run with a custom release function as you can make any edit you want. environment variables always seem very brittle to me so I don't use them ever

thheller14:01:59

actually I recommend passing variables such as your at runtime rather than build time

thheller14:01:23

ie. call your.app.init({"backend":"foo.bar"}) from HTML

thheller14:01:03

easier to adjust and everything uses the same build. no need to recompile to change backend url (good when you have multiple environments)

grav14:01:06

they certainly are. I have a lot of bash scripts interacting with the aws cli. porting those to cljs would be an option, but the aws apis are often more tedious than the cli.

thheller14:01:39

generating platform specific HTML is generally much easier to generate and test

grav14:01:45

yes, that might be a good option … but i’d need to generate the html then

grav14:01:34

well, a lot of options to evaluate 🙂 in any case, it’s cool how flexible shadow-cljs is!

👍 5
grav14:01:53

do you have any good stories about integrating with AWS Lambda? Currently I’m using serverless together with a cljs-plugin that supports Lumo, but it’s pretty slow

grav14:01:55

I’m wondering if the same plugin could support shadow-cljs instead …

thheller14:01:02

no, not currently. I hope to get the clorurists together funding to better document and enhance support for those

grav14:01:01

Ok. I see there’s already a GH issue about supporting Shadow-cljs. https://github.com/nervous-systems/serverless-cljs-plugin/issues/15

thheller14:01:04

I haven't used AWS at all so can't comment on anything related

thheller14:01:26

I did a few tests regarding the zeit now platform recently and that was pretty easy

thheller14:01:42

but AWS is a bit more complicated than that I guess

grav14:01:16

Oh that’s pretty interesting. Maybe now could be an option for my use-case. I’ll have to look into that.

thheller14:01:04

in that example I just do shadow-cljs release now-lambda and cd output-dir; now

thheller14:01:40

pretty smooth overall. I'm still thinking about creating a custom builder for their platform so that you don't have to compile locally at all

thheller14:01:50

but currently that seems like a bit of overkill given how easy it already is

grav14:01:35

Sure. I’m building on an AWS Fargate instance currently which just has a copy of my local setup and checks out the source. Pretty generic

grav14:01:46

And cheap 🙂

grav14:01:28

But of course, leaving even that to http://zeit.co would be a lot easier.

thheller14:01:21

here is one setup using travis to build and push to zeit from there https://github.com/jntn/haiku/blob/master/.travis.yml