This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-08
Channels
- # announcements (6)
- # babashka (78)
- # beginners (84)
- # bristol-clojurians (5)
- # calva (50)
- # chlorine-clover (45)
- # cider (14)
- # clj-kondo (18)
- # cljs-dev (2)
- # clojars (2)
- # clojure (387)
- # clojure-android (3)
- # clojure-europe (6)
- # clojure-gamedev (3)
- # clojure-germany (3)
- # clojure-nl (18)
- # clojure-spec (5)
- # clojure-uk (36)
- # clojurescript (8)
- # clojurex (1)
- # conjure (1)
- # css (1)
- # cursive (32)
- # data-science (1)
- # datomic (11)
- # docker (61)
- # duct (17)
- # emacs (7)
- # figwheel-main (3)
- # fulcro (19)
- # jobs-discuss (3)
- # joker (1)
- # leiningen (23)
- # malli (11)
- # mount (6)
- # off-topic (30)
- # pathom (14)
- # pedestal (2)
- # phzr (1)
- # re-frame (11)
- # reagent (3)
- # reitit (5)
- # ring-swagger (3)
- # rum (1)
- # shadow-cljs (113)
- # slack-help (9)
- # spacemacs (16)
- # specter (4)
- # sql (14)
- # vscode (2)
- # windows (3)
- # xtdb (12)
Hi. Can I use :compiler-options :output-to to specify a relative path for the production build script with :target :browser ?
I realize I can just move the file with a separate shell command but it would be much neater to be able to specify the file name
instead of having to use the namespace (which means atm I get main.js, but I guess that will change too)
@ashnur can you use :release {:output-dir "build/js"}
? I only learned of this option recently myself.
yeah you can just configure a different output-dir for release builds, see https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration
thanks, i will just use another process externally to move the files to their appropriate place with their appropriate name then
if you want main-production.js
or whatever it is advised to use a different directory for ALL files
sure, that's not a problem, but I still can't change the filename, just because other files are there too
as it stand, I still need something else externally to find the file and rename it, so I need additional tooling
This is what I took that 'hardcoded, can't be changed -> filename must be the same as the namespace'
@thheller you explained well, but I misunderstood, {:output-dir "../dist" :modules {:new-filename {:init-fn app.core/main}}}
creates ../dist/new-filename.js
I am sorry for being thick headed at first
now my only worry is that shadowcljs might overwrite something, but "luckily" production build assets are also in git so at least it's visible if it happens 🙂
it would mean that I have to rewrite gazzillionn legacy stuff in a huge django project that's over 8 years old that uses dist to publish everything
ashnur I have ClojureScript (shadow-cljs) working along side Django successfully. I managed to get it working through judicious use of the static folders sytem of Django where multiple folders are seen by the browser as a single folder. Ping me if you need more details or my config.
Basically while you are dev'ing on local one version of your .js file is used from the dev folder as it has static-files precedence, whilst on live the committed version is used instead.
I just woke up, it's 4:10 AM : ) Just to explain why I didn't ask immediately. This sounds very useful, I can manually configure both the dev and the prod files and what is committed is going to get published (by hand), but something that requires less attention and is less error-prone would be nicer
@ashnur my setup is as follows:
the cljs project is in a folder called ui
at the top level. its shadow-cljs.edn
specifies :output-dir "static/dev/admin-ui"
(note the "dev" folder). I have :release {:output-dir "static/admin-ui"}
(note the lack of "dev". Then in my Django settings:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_DEV = os.path.join(BASE_DIR, "ui", "static", "dev")
STATICFILES_DIRS = []
if os.path.isdir(STATIC_DEV):
STATICFILES_DIRS += [STATIC_DEV]
STATICFILES_DIRS += [os.path.join(BASE_DIR, "ui", "static")]
What this does is cause /static/
to resolve files in ui/static/dev
and also in ui/static
and the "dev" variant only exists on my local while running npx shadow-cljs watch app
. It never appears on the live site. Note that ui/static/dev
and ui/static
appear to be overlayed, so if you request /js/main.js
it will first look relative to the dev folder, and then look relative to the other non-dev folder.this is almost funny, twice in a row is a pattern : ) Thanks for the config, I shall try it right away
It's a bit more complicated because I am trying devcards, so those need a place too, but I don't want to build them for productions, and tests that I do want to build for production.
Ok, so the trick really is in the static resolution order in django, using /dev/ when there is one instead of always using the prod version which might exist during dev time too
I am trying to sneak in something on the back door, if I have to work on this 2 weeks just to get the paths right (you can see how slow I am, I am not exxargerating), it will not work : )
of course it would get published in a subdirectory too, you are entirely correct in everything you said 🙂
in like 8 years since I've been trying to use clojure(script) for work, this is the first time I think I will succeed, it's thrilling
I'm switching a cljs react-native project from lein/clj/clj-rn to shadow-cljs. I got the dev and build working but I'm struggling with the tests. Previously the react-native libs were mocked by importing dependencies in a namespace. That namespace would be at different source path, one for the project code with requires, and one for the test with mocks of the functions that are called in tests. Now with shadow-cljs since the imports are made directly in the require I'm not sure how to proceed to mock these imports
this is the old project.cljs https://github.com/status-im/status-react/blob/develop/project.clj with mocked dependencies https://github.com/status-im/status-react/blob/develop/test/cljs/status_im/react_native/js_dependencies.cljs and test runner https://github.com/status-im/status-react/blob/develop/test/cljs/status_im/test/runner.cljs
most of the time they don't even happen because most tests are testing the map of effects outputed by events without applying them (so no effects occur)
does this ns still exist? https://github.com/status-im/status-react/blob/develop/test/cljs/status_im/react_native/js_dependencies.cljs
this ns was the mock, in any case I couldn't use the same method with shadow since you can't define different src-path for different builds, which was how it worked
so you can use the mocked ns and call it (ns status-im.react-native.js-dependencies-mock)
then in your build config use :build-options {:ns-aliases {status-im.react-native.js-dependencies status-im.react-native.js-dependencies-mock}}
that would make every namespace that references the js-dependencies
use the mock instead
if each ns has the requires directly you can use the :resolve
option to mock things https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve
or use :js-options {:js-provide :require}
(assuming its a :browser
) build and provide your own require
fn that returns the mocks
so something like <script>window.require = function(name) { if (name == "foo") { return {} } else ... }; </script>
ideally I'd like to keep the requires directly in the ns declaration "shadow style", and keep the tests as vanilla cljs as possible so I'll look at js-options and js-resolve
resolve will be rather verbose and since you are likely going to override all of them it might be better to just create a custom require
fn
Hi! I’m having an issue when using schema-generators along with shadow-cljs. If I use clojurescript version 1.10.520 with shadow <= 2.8.83 everything works. If I bump clojurescript to version 1.10.597, or keep the version 1.10.520 but bump shadow-cljs to 2.8.84 I start to get the error Couldn't satisfy such-that predicate after 10 tries
when trying to generate a schema.
I’m asking for help here because if I use clojurescript version 1.10.597 and the cljs.build.api everything works fine. Do you have any clue about what may be happening?
I thought it could a dependecy issue, but I compared both dependency trees (printed with lein deps :tree
) and the tree using version 2.8.83 and 2.8.84 are identical (with exclusions loom pathom and core.async). Maybe I’m missing something when checking the dependencies. I have a sample project reproducing the issue at:
https://github.com/felipethome/sg-issue
make sure you get these versions
[com.google.javascript/closure-compiler-unshaded "v20191027"]
[org.clojure/google-closure-library "0.0-20191016-6ae1f72f"]
[org.clojure/google-closure-library-third-party "0.0-20191016-6ae1f72f"]
Still the same problem here
Unfortunately I can’t stop using lein at this moment. Thank you! I will try to investigate more
Is it possible to specify different configs before build for
shadow-cljs watch app
And
shadow-cljs release app
I different config-variables for each environment. On the serverside I use yogthos/config with lein. And I simply specify which profile to use.https://shadow-cljs.github.io/docs/UsersGuide.html#_release_specific_vs_development_configuration
So you do it directly in shadow-cljs.edn?
That’s a little bit to awesome for my taste Mr @thheller 🙏 You sir are a legend, and so is shadow-cljs
How do I access the config variables inside my cljs files?
Boom 💣
thanks
ashnur I have ClojureScript (shadow-cljs) working along side Django successfully. I managed to get it working through judicious use of the static folders sytem of Django where multiple folders are seen by the browser as a single folder. Ping me if you need more details or my config.