Fork me on GitHub
#shadow-cljs
<
2017-12-05
>
jose10:12:46

As I understood it, from this article on the wiki: https://github.com/thheller/shadow-cljs/wiki/Custom-builds I can create a custom build to add some extra steps to the build process, e.g. compile sass to css. Once I have a custom build I can start it with a command like shadow-cljs watch compile-css app , where app is the build targeting the browser. Is it correct? or what is the recommended way to add some extra steps to the build (e.g. compile sass)?

thheller10:12:06

yes you can do this but shadow-cljs is meant to compile CLJS/JS

thheller10:12:13

the requirements for css are entirely different

thheller10:12:29

that being said if you just want to run a function that does the css

thheller10:12:35

you can hook that into your target

thheller10:12:53

I recommend to start by calling shadow-cljs clj-run your.css/build manually

thheller10:12:47

that fn can use (shadow.cljs.devtools.api/get-build-config :app) if it needs the config

jose10:12:13

ok, thanks, my idea is to add a custom build to be able to build a complete website with just one command

thheller10:12:51

the issue with this is that css has completely different concerns than CLJS

thheller10:12:24

CLJS gets recompiled a lot during development (and hot loaded)

thheller10:12:34

triggering a CSS compile on every CLJS compile is bad

thheller10:12:40

(as is the reverse)

thheller10:12:49

since it does too much work

thheller10:12:02

so you really just want two independent things to run in parallel

thheller10:12:56

I do have my own sass utils in my project where I do this

thheller10:12:39

I understand the desire to make it part of the build but I don’t recommend starting with that

thheller10:12:46

make a standalone function that does what you want

thheller10:12:10

integrating that into a custom target is much simpler later

jose10:12:28

so you have 2 different processes, one watching CLJS and other the CSS?

thheller10:12:46

2 threads on the same JVM

thheller10:12:45

I have not yet settled on a proper API for “plugins” but sass would probably be a plugin

jose10:12:10

are there plans to provide an api for plugins for shadow-cljs? that would be cool

thheller10:12:21

yes. the basic theme will probably be like this: you provide a function for shadow-cljs to call when starting

thheller10:12:41

that function in turn can modify the server and register additional “hooks” it wants

thheller10:12:50

eg. call this function when a dev build is started

thheller10:12:58

call this function when a release build is started

thheller10:12:56

but … write plain clojure code with no dependecy on shadow-cljs until you REALLY need to

thheller10:12:19

there are too many tool-specific tools already, that needs to end.

thheller10:12:33

everything you write should also work in lein (and boot and tools.deps clojure)

jose10:12:36

just one more question, the wiki article says The state is a clojure map representing the full shadow-build compiler state. TBD: open an issue if you want to know more about this. can you point me to where to find more info about it?

thheller10:12:33

anything specific you want to know? there are no docs for this apart from the code itself

thheller10:12:42

shadow.build.data has some utility functions

jose10:12:27

just a link to some code to start to look into it is fine

jose10:12:17

thanks a lot for all the info, really enjoying shadow-cljs and looking forward to the plugin api 🙂

thheller10:12:19

its all pretty CLJS/JS specific and CSS is a whole lot simpler

thheller10:12:42

write a plain function to compile css and you don’t even need a plugin API

grav12:12:20

Is there some kind of hook that shadow-cljs calls after it recompiles in watch mode?

thheller12:12:41

hook to do what?

thheller12:12:48

none currently but I can add one easily. just need a use-case to justify it 😛