shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Janis Peisenieks 2021-04-17T10:44:18.280900Z

Hello folks! I’m pretty new to shadow-cljs, but I’m curious - is there a way to add a preamble to the generated js file? https://shadow-cljs.github.io/docs/UsersGuide.html#compiler-options, but I’m curious if I’m missing something. My use case is that I’d like to add a link to a file with the licenses of the OpenSource libraries I’ve used

thheller 2021-04-17T10:49:10.281500Z

@janis each module can have a :prepend "some-string"

Janis Peisenieks 2021-04-17T10:51:38.282Z

🤦 Thank you @thheller

conan 2021-04-17T13:44:52.282500Z

Hello I've been struggling with some type inference:

(let [^js data (.data author-post)
      postRef (.-post data)]
  )
gives me Cannot infer target type in expression (. inst_51072 -post) but if I do this
(defn get-data
  [^js o]
  (.data o))

(let [data (get-data author-post)
      postRef (.-post data)]
  )
it works. any ideas why? there's something i'm not understanding, and any advice would extremely appreciated!

conan 2021-04-18T21:33:39.310900Z

oh! well that is surprising. thanks for the sleuthing!

👍 1
conan 2021-04-17T13:54:31.283100Z

using

(aget data "post")
works too, but i'm cargo-culting the belief that this is bad

lispers-anonymous 2021-04-17T14:25:22.283400Z

Is the let inside a go block?

conan 2021-04-17T14:31:03.283600Z

yes, this is all inside a go block

lispers-anonymous 2021-04-17T14:33:12.283800Z

Type hints in clojurescript can get lost in go blocks. The best thing to do is extract things out into functions like you have here. I believe it is an issue with the go block macro

lispers-anonymous 2021-04-17T14:33:27.284100Z

I will try to find a source of this for you

2021-04-17T16:12:57.291400Z

Hi all, investigating migrating to shadow-cljs for our builds and in the processes of piecing together our previous workflows. Specifically, we we had one project that depended on another. Previously we would use webpack to produce a js bundle, and then include it as a :foreign-lib, telling the cljs-compiler what namespace it :provides. We could then put this bundle in in the dependency jar, and then have access to those same foreign libs in the dependent project. The shadow browser target operates on the node_modules folder. Is there some recommended approach to coordinating these kinds of transitive js dependencies with shadow?

thheller 2021-04-17T16:43:35.291900Z

@zalky if you want to continue using webpack I'd suggest using :js-provider :external as described here https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html#option-2-js-provider-external

thheller 2021-04-17T16:44:37.292600Z

you'd still need to replace your :foreign-libs setup probably though. shadow-cljs does not support those as they are in general not required and problematic when mixing with npm dependencies

2021-04-17T16:49:03.292800Z

Thanks @thheller for the link! Giving it a read now. I don't suppose it makes any sense to package node_modules itself into the jar file, and have shadow access it from the depedent's classpath?

2021-04-17T17:13:05.293Z

Ok, just to see if I've understood the implications of your blog post in the context of a dependent project, I could try something along the lines of: 1. Configure the dependency project with :js-provider :external 2. Generate libs.js via webpack 3. Package libs.js in the dependency jar 4. Configure the dependent project with :js-provider :external 5. Include the libs.js along with the depedent's main.js Have I got the right idea?

thheller 2021-04-17T17:20:25.293200Z

no, that sounds wrong

thheller 2021-04-17T17:20:46.293400Z

first of all: why webpack? do you include other non CLJS stuff or is it purely for bundling npm dependencies for use by CLJS?

2021-04-17T17:58:11.302400Z

@thheller, purely for bundling npm dependencies. Doesn’t have to be webpack, but before shadow it was the simplest approach to managing the npm dependencies between our two projects. Our dependant project didn't really have to worry about any npm workflows. It could just rely on the bundle to have the correct version of everything. Definitely open to other workflows that shadow may enable.

thheller 2021-04-17T18:00:35.302600Z

well just letting shadow-cljs handle the npm dependencies will be straightforward (well depending on which packages you use). letting webpack do that will require much more configuration

2021-04-17T18:44:17.306500Z

That would be ideal but would that require introducing a package.json into the dependant project and ensure all the transitive npm dependencies are installed in the dependant project?

2021-04-17T19:04:53.307100Z

A bit more context if it helps: we have a full-stack clojure application with backend, frontend and sass that is all bundled as a framework and deployed in different domain specific contexts. These domain specific applications extend the core one. The core app is really easy to bring into a new project as a dependency, the biggest pain point was the npm modules that the core app requires. Bundling these with webpack, and then including the bundle in the jar meant that anyone working the domain specific applications would not have to worry about npm workflows. You do have to declare your foreign libs :provides in the dependent project, but this seemed easier than having package.json track transitive dependencies and then having to manually sync npm installs.