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
@janis each module can have a :prepend "some-string"
🤦 Thank you @thheller
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!oh! well that is surprising. thanks for the sleuthing!
using
(aget data "post")
works too, but i'm cargo-culting the belief that this is badIs the let inside a go block?
yes, this is all inside a go block
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
I will try to find a source of this for you
Here is one: https://increasinglyfunctional.com/2021/01/28/clojurescript-type-hinting-core-async-gotcha.html
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?
@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
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
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?
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?
no, that sounds wrong
first of all: why webpack? do you include other non CLJS stuff or is it purely for bundling npm dependencies for use by CLJS?
@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.
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
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?
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 install
s.