shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
martinklepsch 2020-12-10T11:29:33.400800Z

Would it be possible to write a Closure-compatible JS namespace that merely requires (and exports) a different set of NPM dependencies? I’d like to do this to provide different (API compatible) packages based on node/browser.

martinklepsch 2020-12-10T11:30:36.400900Z

I know that shadow can help with it’s :node reader conditional but the issue with that is that that forces the namespace to be .cljc and our code isn’t necessarily valid Clojure (it uses js/ etc)

thheller 2020-12-10T11:38:27.405600Z

as long as you don't load that namespace in CLJ thats not a problem?

thheller 2020-12-10T11:39:02.406Z

I don't understand your question though. why would it need to be closure js?

Ernesto Garcia 2020-12-10T11:39:16.406400Z

Hello. We have an existing AngularJS app bundled with Browserify. We have created a re-frame cljs view for to embed in the existing app. Using shadow-cljs, we are able to build into an :npm-module target, and bundle everything together, but we don't have the convenient auto-reload and REPL from shadow-cljs. I would therefore like to target :browser. It can be set up so that shadow-cljs bundles separately from Browserify. How would I achieve bundling all together?

thheller 2020-12-10T11:40:43.406900Z

@ernesto.garcia you can use :external an let that file be processed by browserify as usual https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider

Ernesto Garcia 2020-12-10T11:42:33.408100Z

I'll look into that. Is there also a way for shadow-cljs to bundle the JS files, and not use Browserify at all?

thheller 2020-12-10T11:43:09.408600Z

don't know. haven't looked at angular in a really long time

thheller 2020-12-10T11:43:24.409Z

likely has some browserify plugin to process stuff right?

Ernesto Garcia 2020-12-10T11:43:59.409800Z

I think we are not doing any interesting processing, just bundling

Ernesto Garcia 2020-12-10T11:44:35.410400Z

Shadow-cljs is able to deal with JS code directly when put in :source-paths?

thheller 2020-12-10T11:44:52.410700Z

when its is standards-compliant JS yes

Ernesto Garcia 2020-12-10T11:45:59.411300Z

Ok, I will look into your responses. Thanks a lot for your support!

martinklepsch 2020-12-10T11:46:35.411400Z

We use linters and other tools that cause trouble in this situation. Maybe we could configure them to only look at things from a CLJS perspective but it also just feels a little… unintended to me to to have a bunch of Clojure namespaces

martinklepsch 2020-12-10T11:47:02.411600Z

And Closure JS because my understanding is that that’s the only thing I can load as if it’s a ClojureScript namespace in my ClojureScript code?

thheller 2020-12-10T11:48:09.411800Z

I'm not entirely sure what you are asking here

thheller 2020-12-10T11:48:39.412Z

what problem are you trying to solve exactly?

thheller 2020-12-10T11:49:19.412200Z

I have seen plenty of projects that use CLJC for everything but only actually working on one platform so its not uncommon

thheller 2020-12-10T11:52:34.412500Z

I also wrote this a while ago. while incomplete it may give you an idea how to solve "platform specific" code without relying in compiler hacks

martinklepsch 2020-12-10T11:55:03.412900Z

Yeah, for sure. And it’s working. I’m just trying to understand if there might be a different way that would remove the reader conditionals and move the conditional loading into an external file. Maybe I could also just have a designated namespace that re-exports the relevant requires. I guess the effect would be the same as having a Closure namespace.

martinklepsch 2020-12-10T11:56:10.413100Z

That said I like the idea of the Closure namespace it would mean we’re closer to “stock” Clojurescript

martinklepsch 2020-12-10T11:57:11.413300Z

Just to be clear I’m not trying to solve a pressing problem here I guess. It’s more about exploring alternative approaches to learn

thheller 2020-12-10T12:31:24.413500Z

I do not understand which problem you are trying to solve. what does conditional loading mean to you? practical example?

thheller 2020-12-10T12:33:39.413700Z

isn't control via the build config enough? https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve

martinklepsch 2020-12-10T14:41:28.414200Z

oh that js-options thing actually looks like it might just do what I’m looking for