Fork me on GitHub
#shadow-cljs
<
2021-04-17
>
Janis Peisenieks10:04:18

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

thheller10:04:10

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

conan13:04:52

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!

conan13:04:31

using

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

lispers-anonymous14:04:22

Is the let inside a go block?

conan14:04:03

yes, this is all inside a go block

lispers-anonymous14:04:12

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-anonymous14:04:27

I will try to find a source of this for you

conan21:04:39

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

👍 3
zalky16:04:57

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?

thheller16:04:35

@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

zalky16:04:03

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?

zalky17:04:05

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?

thheller17:04:25

no, that sounds wrong

thheller17:04:46

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

zalky17:04:11

@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.

thheller18:04:35

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

zalky18:04:17

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?

zalky19:04:53

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.

thheller16:04:37

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