This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-23
Channels
- # announcements (7)
- # babashka (40)
- # babashka-sci-dev (74)
- # beginners (74)
- # calva (31)
- # cider (11)
- # clj-kondo (22)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (70)
- # clojure-brasil (3)
- # clojure-dev (12)
- # clojure-europe (39)
- # clojure-nl (2)
- # clojure-norway (15)
- # clojure-uk (9)
- # clojurescript (69)
- # community-development (2)
- # conjure (1)
- # core-async (3)
- # cursive (1)
- # data-science (1)
- # datalevin (13)
- # datomic (17)
- # emacs (42)
- # events (1)
- # fulcro (16)
- # graphql (9)
- # helix (1)
- # holy-lambda (14)
- # honeysql (2)
- # hugsql (3)
- # hyperfiddle (5)
- # kaocha (10)
- # lsp (41)
- # luminus (5)
- # malli (7)
- # meander (3)
- # membrane (47)
- # off-topic (23)
- # podcasts (2)
- # polylith (34)
- # rdf (4)
- # re-frame (2)
- # releases (2)
- # remote-jobs (1)
- # ring (16)
- # shadow-cljs (111)
- # spacemacs (6)
- # test-check (2)
- # tools-deps (19)
Should the newly available :as-alias in Clojure 1.11.0 work with Clojurescript in a shadow-cljs setup? And if it isn’t working for me, is it because shadow-cljs is using an older version of Clojure?
it works regardless of clojure version. if it isn't working you are likely on an old version of shadow-cljs.
Well I’m using [email protected] installed via npm, but none of the dependencies in shadow-cljs.edn say anything about which version of Clojure to use. Do I need to explicitly add Clojure as a dependency there?
Nope, that doesn’t work, the message says it is ignored and default version is used to ensure compatibility.
shadow-cljs supports this on its own. neither the clojure nor clojurescript version matters. just use it.
Sorry to necropost, but from my investigations this morning it seems that shadow-cljs supports :as-alias
within ns
but not within a free-standing (require '[foo.bar :as-alias bar])
.
Could this be caused by something else?
> shadow-cljs info
shadow-cljs - config: /home/ae/src/ablution/cljs/ablu.ui/shadow-cljs.edn
=== Version
jar: 2.17.8
cli: 2.17.8
deps: 1.3.2
config-version: 2.17.8
> shadow-cljs watch app
shadow-cljs - HTTP server available at
shadow-cljs - server version: 2.17.8 running at
shadow-cljs - nREPL server started on port 3333
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
------ ERROR -------------------------------------------------------------------
File: /home/ae/src/ablution/cljs/ablu.ui/src/ae/ablution/ui/core.cljs:11:1
--------------------------------------------------------------------------------
8 | [ae.ablution.address.interface.spec :as a.spec]
9 | [ae.ablution.ui.views :as views]))
10 |
11 | (require '[foo.bar :as-alias bar])
-------^------------------------------------------------------------------------
null
Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: [foo.bar :as-alias bar] at line 11 ae/ablution/ui/core.cljs
--------------------------------------------------------------------------------
12 |
13 | (defn ^:export init
14 | []
15 | (router/start!)
--------------------------------------------------------------------------------
Support require outside of ns: https://clojure.atlassian.net/browse/CLJS-1346?oldIssueView=true
that doesn't do what you think it does and has been shown to create many more problems than it solves
don't try to get creative with require
ouside ns
that ultimately doesn't end up working
Thank you for defclass
! I had been struggling with js/Reflect.construct
gobj/extend
js/Object.create
js/Object.assign
(.call Class this props)
and nothing seemed to go the way I wanted. At first defclass also seemed to not work but figured it out just fine eventually!
So I'm using an NPM module — https://github.com/react-syntax-highlighter/react-syntax-highlighter — for syntax highlighting, which has built-in support for two different syntax highlighters (Prism.js and Highlight.js). Taken together, these highlighter packages together with all their supported languages are quite weighty — over 1MB of built code.
To avoid pulling in stuff I'm not using, I'm using PrismLight
(as described under "Light Build": https://github.com/react-syntax-highlighter/react-syntax-highlighter#light-build), which is meant to only pull in Prism.js itself plus languages that are explicitly specified.
Yet, both Prism.js and Highlight.js, together with all the supported languages are included in my shadow-cljs build output. What can I do to avoid this?
@U05224H0W any advice on how to use webpack to sort this out? I tried using option #2 at https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html, but this still seems to cause the entire package to be included (I believe the relevant line in the output target/index.js
is ALL["react-syntax-highlighter"] = require("react-syntax-highlighter");
)
sorry, what is not supported? 🙂
using webpack to fix this?
yeah I'm actually doing that now
hey that worked, thanks!
@U05224H0W while I have your attention, do you think it would be possible to use the "Async Build" option described at https://github.com/react-syntax-highlighter/react-syntax-highlighter#async-build with shadow-cljs, or do something similar?
https://code.thheller.com/blog/shadow-cljs/2019/03/03/code-splitting-clojurescript.html.
I mean, I am using code splitting and it's great, but... wouldn't I have to manually create a module for each language?
because there are a lot of them: https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_PRISM.MD
ideally yes
I guess you could write something to generate a build config for you or a custom :target
users should ideally be able to highlight any code they want
okay, let's say I wanted to create one module per language—could I do that in shadow-cljs.edn
only, or would I create a cljs file for each separate language?
AFAICT it should just 'magically' work — somehow it loads languages lazily when you create corresponding reagent components
this is kind of over my head though, so I'm not sure from looking at the code how exactly it works
you mean I'd use that import with method #2 from your blog post?
alright, I tried that and it doesn't seem like webpack does any code splitting automatically
I'm trying to see if there's something I need to configure in webpack...
the problem seems to be that the prism-async thing doesn't actually load languages async
anyway, I think I might try using shadow-cljs to split the languages out as modules myself
seems like a fun exercise
@U05224H0W is there any support for writing code to generate a shadow-cljs config? or to merge config from multiple files? (so I don't have to clutter up my current shadow-cljs file)
eh nevermind, I typed it out and it wasn't too bad
yes, webpack also needs to be setup to code split. and the async loading can only work if the bundler (ie. webpack) bundled the code accordingly. in webpack this is done via dynamic import in the code. in the closure compiler things are configured via :modules
statically.
no you cannot generate the config with the default targets. but you could create a "wrapper" target that generates config in CLJ code and then just delegates to the regular :browser
target or so. this is non-trivial and will require digging fairly deep into the internals of shadow-cljs though 😛
got it
fwiw setting up dynamic language loading with shadow-cljs was pretty straightforward
shadow.lazy helped a bunch
the only annoying part was that some of the language packs turned out to depend on other language packs (so I had to set up dependencies between modules accordingly)
...also, would it be possible to use the "Async Build" (https://github.com/react-syntax-highlighter/react-syntax-highlighter#async-build) with shadow-cljs?
Does anyone have problems with tick for release compilation? With :simple
optimizations I get
java.time.OffsetDateTime = java.time.goog$module$goog$object.get(module$node_modules$$js_joda$core$dist$js_joda, "OffsetDateTime");
java.time.OffsetTime = java.time.goog$module$goog$object.get(module$node_modules$$js_joda$core$dist$js_joda, "OffsetTime");
module$node_modules$$js_joda$core$dist$js_joda
lacks both OffsetDateTime and OffsetTime. Currently running on 5.2.0
for @js-joda/core
, and they should be there from what I can tell. All other modules are existingI suppose this speaks volumes about how much I trust shadow-cljs o_O. rm -rf node_modules && npm i
solved the problem
Does shadow have the equivalent of the leiningen checkouts folder usage? ie, some way I can edit a library and have the changes picked up on the next build without installing? Working on my mxWeb Trainer app I am coming up with tweaks for Matrix and mxWeb often enough that that would grease the skids a bit. Not that a local deploy install
is the end of the world. (They are leiningen projects.)
Ohh how does your local deploy solution work? I am also developing a library in parallel to my app, and so far I'm just doing extensive testsing and Clojars releases. Would be nice to short circuit that a bit.
Big caveat @UPHKPR2A3: I know little about CLJ tooling! Anyway...
My two changing dependencies are lein
projects, so I can do lein install
and have either refreshed in a few seconds.
The bad news is, I still have to reboot the shadow watch and server to pick up the changed jar. Unless I am missing something.
And I do not know if you can take advantage of lein install
, or if shadow has the equivalent. This, however, looks encouraging: https://shadow-cljs.github.io/docs/UsersGuide.html#publish-lein And there may well be a simpler shadow command the cognoscenti can provide.
"just use lein"
Sounds like heaven. I did not realize that would work. To me the build process is a mystery, esp. because I did not come from a Java/JAR/Maven background. I just find "starter" projects for a given build tool, or for leiningen do lein new app
, and get on with my coding with my fingers crossed.
Does "just use lein" mean:
• create a minimalist project.clj as documented in https://shadow-cljs.github.io/docs/UsersGuide.html#publish-lein
• then lein deps
will Do the Right Thing? Including maintaining, pom.xml
, I see?
• or is it just for lein deploy clojars
?
• will checkouts work automagically as long as I run lein deps
after a change to the contents of checkouts?
Thx!
you use lein
as you normally do. so you put your :dependencies
and :source-paths
in project.clj. then add the checkouts you want to that project. then you also add the thheller/shadow-cljs
dependency to that project.clj
.
in shadow-cljs.edn
you set :lein true
or :lein {:profile "+cljs"}
(if you use a leinigen profile)
that will make shadow-cljs use lein to create the classpath and launch the JVM. so since lein is in charge checkouts just work
Yeah I was in the wrong section, and now that I see it don't know how I missed it! Thx for your patience!
How does one upgrade shadow-cljs to use clojurescript 1.11.4? Dying to use the :as-alias in requires
Is it that you wait until there's a shadow-cljs version built with 1.11.4 and it handles itself?
also note that there is no cljs release with :as-alias
support yet. 1.11.4 is not it.
@U020G0VEL75 I was having some trouble with this same thing earlier, and it turned out that even though I had the latest version of shadow-cljs installed locally in my project, I was invoking the global install of shadow-cljs at the command line, and that global install was quite old. I updated the global install, and also changed my habits to invoke the local install going forward.
Is there a way to create a “vendor” module which includes all 3rd party dependencies? Would be helpful in reducing load times for very large CLJS apps. Like https://blog.jakoblind.no/code-split-vendors-with-webpack-for-faster-load-speed/
possible yes, helpful unlikely. better to properly split your code so parts no used initially aren't loaded in the initial download
splitting all 3rd party libs likely won't help since it'll still load all of them together anyways then
https://code.thheller.com/blog/shadow-cljs/2019/03/03/code-splitting-clojurescript.html has some suggestions that might help
Was that sample project published anywhere? I can’t see the source to lazy-component
?
Would be helpful in the sense that the vendored bundle will not get cache-busted as often as the app
you can go with option #2 described here and actually use webpack https://code.thheller.com/blog/shadow-cljs/2020/05/08/how-about-webpack-now.html