Fork me on GitHub
#boot
<
2017-12-19
>
justinlee18:12:06

How does boot choose the entry point to my code? (I’ve set up my project using tenzing so I’m not sure how all of this works together.) I see that the reload task has a :on-jsload option that points to a function in my code, but if I wasn’t in development mode, what sets the top-level entry point?

micha18:12:29

@lee.justin.m top level forms in build.boot are evaluated

micha18:12:16

if you want to make a script that has a definite entry point, with command line arguments and so on, you can define -main as a top level var in your boot script

micha18:12:54

but this, for example, will be a working build.boot file:

(.println System/out "hello world")

micha18:12:28

if you're building a project the entry point is usually set via the command line, like boot dev for example

micha18:12:45

the entry point would be the dev task

micha18:12:11

which is probably defined in build.boot or in a library required by build.boot

justinlee18:12:49

yer bakin’ my noodle. so the entry point to a program is actually the toplevel of build.boot?

justinlee18:12:04

I had assumed that when I run boot build, boot runs, reads some stuff, fires off some compilation, and then emits some javascript in an output directory.

justinlee18:12:51

What confuses me is that the template sets up an app.cljs which has nothing except defns at the top level. I would have expected at least one function invocation at the toplevel so the program knows where to start.

micha18:12:58

when you run boot build then the build task is the entry point, in a way

micha18:12:16

the build.boot file is evaluated, then if there is no -main function defined in the build.boot it tries to execute the build task, because that's what was passed on the command line

micha18:12:21

does that make more sense?

micha18:12:54

inside the build.boot file are expressions that load dependencies, define tasks, require namespaces, etc

justinlee18:12:35

Yes. I think the answer is that this will not work in production. The only reason this is working now is because in the development run, the auto-reloader task has been informed as to where the entrypoint is. I’ll have to set up a webserver to test the theory though.

justinlee19:12:09

Well I’m wrong. I don’t understand how this works. 🙂

micha19:12:26

oh wait, you're talking bout the entry point to your web application?

micha19:12:34

or to the boot build program?

justinlee19:12:52

to the web application

micha19:12:58

oh ok sorry

micha19:12:34

see :init-fns

micha19:12:05

i think in most cases the build task can create the .cljs.edn file, or you might have one in the project

justinlee19:12:51

ah! yes that’s it. in the build output it creates an app.cljs.edn that points to the init function

micha19:12:58

that's an example you can look at

micha19:12:25

yes, you shouldn't need that once you've built your project for production

micha19:12:29

it's only needed at build time

justinlee19:12:37

oh yea tenzing created one in the resources directory. I’m not entirely sure why there is so much stuff in the target directory after a production build

micha19:12:58

it's mostly because of source maps

micha19:12:14

you can remove most of it if you don't care about source maps

micha19:12:26

the main.out stuff

justinlee19:12:48

got it okay. thanks for solving that mystery for me. this was one of those things where I questioned my basic comprehension of how clojurescript works

micha19:12:24

haha i hear ya