Fork me on GitHub
#shadow-cljs
<
2018-01-19
>
theasp02:01:31

@thheller Is there anyway to keep the npm deps in the config file?

theasp02:01:19

Also, any idea whats up here?

SHADOW import error /home/asp/projects/logview/target/shadow-cljs/builds/server/dev/out/cljs-runtime/macchiato.cookies.js
Error: Cannot find module 'cookies'

tianshu03:01:18

@thheller I got an error said missing instance, how can I get this instance?

tianshu03:01:45

ok, I read the wiki found this can not work in nREPL.

robert-stuttaford05:01:05

@thheller is it possible for me to use shadow in this manner: put all intermediate output in target, but put the final entry point in resources? in prod, we only use a single js in resources. in dev, we do what i just said, and serve target/js at /js in dev time. i’ve got shadow working, but because it puts stuff in resources, it now complains that it’s finding sources twice.

robert-stuttaford05:01:28

ie my working cljsbuild config

:output-to            "resources/app/js/app.js"
                   :output-dir           "target/js/out"
                   :asset-path           "/js/out"

robert-stuttaford05:01:55

dep in the root of the project (not in a profile), a (shadow/start!) call showing shadow-cljs - server running at in my repl. but, when i shadow-cljs watch, i get: ClassNotFoundException shadow.cljs.devtools.cli. what have i forgotten?

robert-stuttaford05:01:46

that’s right after a shadow-cljs - connected to server message

robert-stuttaford06:01:07

does the cljs hot code reloading work without using the built in web server?

robert-stuttaford06:01:21

(i know the docs say css requires the web server)

robert-stuttaford07:01:51

even when using :lein {:profile "+dev"}, :http-handler can’t find my dev profile http handler namespace.

robert-stuttaford08:01:55

@thheller the docs could really do with an example devtools code snippet. i’ve been reading the source to figure out how to give it its options correctly 🙂

tony.kay08:01:31

@robert-stuttaford You reading the new user guide?

tony.kay08:01:43

there is a lot on the devtools section...what option are you trying to figure out?

robert-stuttaford08:01:28

now that i’m reading that edn in github, i can see how output-dir, asset-path and http-root are meant to hang together

tony.kay08:01:02

well, if the user's guide needs clarification, send a PR...glad to improve it.

robert-stuttaford08:01:59

to be clear: the guide has been tremendously helpful in many other ways @tony.kay 🙂

tony.kay08:01:50

thanks, but yeah, we know it is incomplete...it was thrown together from existing stuff and my additions in about 2 days

robert-stuttaford08:01:59

wow. that’s a massive doc for a week’s work

tony.kay09:01:50

like I said, most of the content existed in various places

thheller09:01:40

@theasp npm deps are kept in package.json. libaries can publish a deps.cljs with :npm-deps {"thing" "version"} which shadow-cljs will transfer over to package.json. unfortunately most libaries do not yet do this.

thheller10:01:58

@robert-stuttaford for now just add a require for shadow.cljs.devtools.cli where you require shadow.cljs.devtools.server.

thheller10:01:01

@theasp Error: Cannot find module 'cookies' means you need npm install cookies

thheller10:01:01

@doglooksgood “missing instance” means you probably need to call (shadow.cljs.devtools.server/start!) somewhere to start the embedded server instance

thheller10:01:01

@robert-stuttaford the css and cljs hot loading works without the built-in http server yes. cljs just works, css just requires that you set :watch-dir which should point to the document root of your webserver.

robert-stuttaford10:01:07

rad thanks @thheller will try things

thheller10:01:07

when running the embedded server you can also do everything directly from the REPL if you want

thheller10:01:15

no need to run the CLI

thheller10:01:26

stilll need to write the docs on that though

robert-stuttaford10:01:30

feels like i’m really close to having things set up right. will keep pushing

thheller10:01:05

(shadow.cljs.devtools.api/compile :build) is the same as calling shadow-cljs compile build

thheller10:01:12

every other command translates the same way

robert-stuttaford10:01:45

would the webserver support the use of immutant.web.async, given that you use undertow for the webserver?

thheller10:01:11

the dev http thing no

thheller10:01:49

its just a very thin wrapper for undertow, not using immutant

mitchelkuijpers10:01:45

@robert-stuttaford We also run it embedded for 2 months now works like a charm if you need help let me know

robert-stuttaford10:01:34

i think i just won through!

mitchelkuijpers10:01:39

Awesome we just do this:

(defn start-cljs-repl []
  (shadow-server/start!)
  (shadow/watch :app)
  (shadow/watch :test)
  (shadow/watch :devcards)
  (shadow/nrepl-select :app))

mitchelkuijpers10:01:54

and if something breaks you can just run shadow-server/stop! and restart everything

robert-stuttaford10:01:15

i’m enjoying having fast cli commands with the server running in the jvm. prefer to have the cljs output separate to the web server

mitchelkuijpers10:01:46

Yeah we use cider and emacs, so we like to run some command in emacs which starts everything inside of emacs

mitchelkuijpers10:01:10

and then all the autocompletion works

robert-stuttaford10:01:20

i may even finally learn to use a cljs repl properly

thheller10:01:39

@robert-stuttaford draft-js was among the packages I tested when writing the npm integration. I might be able to help if you have questions.

robert-stuttaford10:01:34

thanks thheller - i’ve got a working spike together 🙂 just getting the css watching working, and then i’m happy i can Build Features

robert-stuttaford10:01:15

kudos on shadow - it’s come a bloody long way since i used your previous toolchain!

thheller10:01:58

hehe yeah. UX was horrible back in those days 😉

thheller10:01:28

switches the current nrepl over to CLJS. so whatever you type next in the REPL will eval in the app build

thheller10:01:13

:repl/quit exits back to the normal CLJ nrepl

robert-stuttaford10:01:17

@thheller any thoughts on splitting the root js from all the extra js output on disk?

robert-stuttaford10:01:38

(cf. my question at 7:07am)

thheller10:01:42

no that is intentionally not allowed

thheller10:01:17

if just creates headaches. it is already separated out into the <output-dir>/cljs-runtime directory

thheller10:01:44

production does not produce or need the cljs-runtime dir so you can ignore that for any release

robert-stuttaford10:01:06

right. the issue is that if i put it all in resources, it’s all on the classpath, and shadow finds its own output and complains about double provides

thheller10:01:06

why do you want to split it in the first place?

thheller10:01:20

right … don’t put it on the classpath 🙂

robert-stuttaford10:01:28

the code is a library project; the jar includes the release js

robert-stuttaford10:01:55

i’ll work it out. just have to find another way 😎

thheller10:01:07

the jar includes compiled js?

robert-stuttaford10:01:50

you include the lib, add its ring handler to your ring app, and it serves the rest turn-key style

robert-stuttaford10:01:00

means the app that uses it need not compile any js

robert-stuttaford10:01:57

its fine, our CI handles building the js and including it. the way i do it with cljsbuild just makes the routing easier.

thheller10:01:37

right you can just output to a directory that is not on the classpath by default

thheller10:01:42

and only added when building the jar

thheller10:01:27

putting compiled things into a jar just seems wrong to me since you now have to restart the server process if you want to update the JS/CSS

thheller10:01:00

but uberjars are nice so I understand why you’d want to do it that way 😉

robert-stuttaford10:01:48

all the stuff inside the box is developed in the library project, with a dev-only web server and repls and whatnot

robert-stuttaford10:01:09

https://github.com/magnars/prone is a good example of how we’re working

robert-stuttaford10:01:38

means we can run this feature set on any of our web visible services. untangling capability from location.

robert-stuttaford10:01:18

@thheller, just confirming shadow does nothing to install npm deps - you have to do that yourself, right?

thheller10:01:04

unless the library you are using properly declares :npm-deps via deps.cljs yes, you have to do npm install

thheller10:01:16

pretty much no library does this as of today

robert-stuttaford10:01:49

is that the consuming library or the consumed library? i guess i should include a package.json with all of these?

{:draft-js             "0.10.4"
 :draft-js-export-html "1.2.0"
 :immutable            "3.7.4"
 :react                "15.6.2"
 :react-dom            "15.6.2"}

thheller10:01:16

please use a string as a name 😉 the consumed library needs to provide this

robert-stuttaford10:01:51

this is my cljsbuild map 🙂

robert-stuttaford10:01:55

i’ll sort, thanks

tianshu10:01:58

@thheller I want to start the build in my nrepl(launched by cider), compile cljs and run clj code in same jvm. is it supported now? didn't found any guide for this.

thheller10:01:52

@doglooksgood see the example @mitchelkuijpers pasted a couple minutes ago. shadow-server is the shadow.cljs.devtools.server ns. shadow is shadow.cljs.devtools.api

robert-stuttaford10:01:12

@doglooksgood

(require '[shadow.cljs.devtools.server :as shadow]
         '[shadow.cljs.devtools.api :as shadow-api])

(shadow/start!)
(shadow-api/watch :app)

thheller10:01:44

I’ll work on the embedding section of the docs, seems like a lot of people want to do this.

thheller11:01:07

that example is incorrect 😉

thheller11:01:26

watch is only in shadow.cljs.devtools.api not the server ns

tianshu11:01:27

yes,I do like this too. but how can I switch to cljs-repl?

tianshu11:01:46

it's likely nrepl-select not work in this case.

thheller11:01:50

ah if you want to use the nrepl started by cider

thheller11:01:10

you need to enable the middleware

thheller11:01:53

@mitchelkuijpers has done that for cider I believe. I do not know how you’d setup the middleware with cider.

robert-stuttaford11:01:31

thanks for the help today!

tianshu11:01:10

I'll take a look

thheller11:01:23

eg. shadow.cljs.devtools.server.nrepl/cljs-select needs to be in your nrepl middleware

tianshu11:01:28

I think if people use leiningen, they probably want do like this.

thheller11:01:45

I recommend using the standalone version which you can cider-connect to. It does all the complicated setup so you don’t have to.

mitchelkuijpers11:01:10

I will send you the middleware @robert-stuttaford but I am currently out for lunch

thheller11:01:11

if someone tells me how to do the other way I can add it to the docs

thheller11:01:52

@mitchelkuijpers @doglooksgood asked for the nrepl stuff but send it to me as well please

tianshu11:01:42

after I add middlewares, it works.

tianshu11:01:30

I saw your shadow-cljsjs project that provide replacements for cljsjs. but the react version is likely use the dev version?

thheller11:01:09

the watch and compile will use the dev version, release will use the release version

thheller11:01:27

you’ll get complaint from react that you are using a minified dev version though

thheller11:01:45

that is not a problem since the release will use the correct thing

tianshu11:01:27

understand

thheller11:01:02

they really don’t seem to expect that someone processes the dev version and doesn’t just use it as they shipped it

thheller11:01:16

need to bug them about that

tianshu11:01:03

the dev version is a little slow, maybe

tianshu11:01:31

however most time we won't debug react.

thheller11:01:15

the dev version does a whole bunch of extra checks to validate you are using everything correctly. most of the time that is useful.

thheller11:01:31

you can override to always use the release version if you prefer

thheller11:01:32

{:resolve {"react" {:target :npm :require "react/cjs/react.production.min.js"}}} (for react v16)

tianshu11:01:07

really awesome feature!

tianshu12:01:52

it will be better if shadow-cljs add these middlewares automatically.

thheller12:01:26

it does if you connect to the nrepl server that shadow-cljs provides

thheller12:01:34

it can’t if you connect to the nrepl server from lein

mitchelkuijpers12:01:00

@thheller @doglooksgood

:repl-options {:init-ns user
                                      :nrepl-middleware [;; provided by fake-piggieback, only because tools expect piggieback
                                                         cemerick.piggieback/wrap-cljs-repl

                                                         ;; cljs support
                                                         shadow.cljs.devtools.server.nrepl/cljs-load-file
                                                         shadow.cljs.devtools.server.nrepl/cljs-eval
                                                         shadow.cljs.devtools.server.nrepl/cljs-select]}}}

theasp13:01:48

@thheller Ahhh! I assumed it was referring to macchiato.cookies, thanks

Alex H21:01:32

what's the best way of building a jar that includes both some backend clojure code (built via the usual lein compile & uberjar) and ideally some shadowcljs-built frontend code?

Alex H21:01:26

maybe some sort of first-step build to put things under resources/, and then do the lein build?

Alex H21:01:05

or is there some better/clever way of doing these things?

thheller21:01:58

shadow-cljs does not yet support building jars so yeah generate the code into some path that is preferably not on the classpath

thheller21:01:11

then run lein to generate the jar (can use a profile to add the path to :resource-paths)

thheller21:01:48

better yet don’t put .js files in .jar. instead serve them directly from a directory if possible. otherwise you’ll need to restart the JVM process every time you want to update the .js.

Alex H21:01:06

somewhat related - is there a stable API of sorts to call shadowcljs from a nodejs script (e.g. gulpfile), to do the build?

Alex H21:01:23

other than shelling out, that is

thheller21:01:58

no JS API available

Alex H21:01:04

ok, that's fair