shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Aron 2021-05-18T03:42:22.002Z

there is a --test= argument for the compiled tests

Aron 2021-05-18T03:42:30.002200Z

if the target is node-test

Franklin 2021-05-18T07:24:30.003600Z

hello, is there any need to have test dependencies in any way separated from the other (runtime) dependencies. Will shadow-cljs automatically remove unused dependencies when I run shadow-cljs release app?

thheller 2021-05-18T07:30:43.005Z

@franklineapiyo your builds only include whatever you :require in your namespaces. having extra :dependencies does not matter when they are not required in your build directly. generate a build report to see what ended up in your build and why https://shadow-cljs.github.io/docs/UsersGuide.html#build-report

👍 1
Franklin 2021-05-18T07:32:13.005400Z

thanks

Margo 2021-05-18T14:01:03.006800Z

Hello, channel! I am trying to generate a js with a hash for my project, but it seems I have no idea how to dynamically include a hashed js file into an html. How do I make sure that my index.html file includes the latest module with a hash if I use

:module-hash-names
?

Margo 2021-05-19T15:34:39.022100Z

I have tried that approach but it looks like unfortunately it doesnt work

Margo 2021-05-19T15:34:47.022300Z

Unless I am missing something

thheller 2021-05-19T15:36:40.022500Z

no way for me to tell without seeing what you did 😛 I know that the implementation works since I use it

thheller 2021-05-19T15:37:32.022700Z

basically you need to have a source html file that has <script src="/js/base.js"></script> tag already

thheller 2021-05-19T15:37:54.022900Z

all the copy does is replace the src path, and only if the source path matches you configured :asset-path + the module name

Margo 2021-05-19T15:38:39.023100Z

right ... Ill try to double check! Thanks for coming back to me so quickly!

Margo 2021-05-19T15:46:25.023300Z

looks like I have the setup correctly, but it still doesnt do the desired thing ...

thheller 2021-05-19T15:47:42.023600Z

what is your :asset-path? what is your script src? and what is your :build-hooks config?

thheller 2021-05-19T15:48:01.023800Z

not that many things affect this so should be easy to find

Margo 2021-05-19T15:48:05.024Z

I have src/index.html file that contains <script _src_="js/compiled/main.js" _type_="text/javascript"></script> tag. I have shadow-cljs.edn that has

:frontend
    {:target :browser
     :output-dir "public/js/compiled"
     :asset-path "/js/compiled"
    ;;  :compiler-options {
    ;;                     ;; add env vars
    ;;  }


     :build-hooks [(shadow-env.core/hook)
                   (shadow.html/copy-file
                    "public/src/index.html"
                    "public/index.html")]


     :module-hash-names true
    ;; ;;  :fingerprint true
    ;;  :build-options {:manifest-name "manifest.json"}
     :modules {:main
               {:init-fn mytherapy.core/init!}}
    ;;  :compiler-options {:externs ["public/js/plugins/"]}
     }

thheller 2021-05-19T15:48:27.024200Z

well there you have it 😛

thheller 2021-05-19T15:48:45.024400Z

you have :asset-path "/js/compiled" but use script src="js/compiled/main.js"

thheller 2021-05-19T15:48:56.024600Z

that needs to match, so switch either

Margo 2021-05-19T15:50:47.024800Z

like (not (= "/js/compiled" "js/compiled)) type of match?

thheller 2021-05-19T15:51:02.025Z

yes, exact match. not only for the purpose of this hook, they should always match

Margo 2021-05-19T15:54:17.025400Z

I dont know, if I switch to <script _src_="/js/compiled/main.js" _type_="text/javascript"></script> and :output-dir "public/js/compiled" and :asset-path "/js/compiled" they do not seem to affect the behaviour

thheller 2021-05-19T15:57:11.026100Z

hopefully the second part about output paths and http makes that a bit clearer

Margo 2021-05-19T15:57:39.026300Z

thanks! Ill read into it!

thheller 2021-05-19T15:57:41.026500Z

very likely you want :asset-path "/js/compiled" and script src="/js/compiled/main.js"

Margo 2021-05-19T15:59:18.026700Z

that is literally what I have

Margo 2021-05-19T15:59:47.026900Z

Margo 2021-05-19T16:00:08.027500Z

ok, actually, needed to clear cache

Margo 2021-05-19T16:00:12.027700Z

now it works

👍 1
Margo 2021-05-19T16:00:22.027900Z

With the paths being identical!

Margo 2021-05-19T16:00:31.028100Z

Thanks a lot! Very useful tip!

Margo 2021-05-18T14:43:04.006900Z

I am trying to get a selmer workaround

thheller 2021-05-18T17:26:21.007200Z

you can use the manifest to generate the HTML you need https://shadow-cljs.github.io/docs/UsersGuide.html#BrowserManifest

thheller 2021-05-18T17:26:47.007400Z

or you can use this hook https://github.com/thheller/shadow-cljs/blob/master/shadow-cljs.edn#L150-L152

thheller 2021-05-18T17:27:18.007700Z

it'll copy the src html and rewrite the script src with the hashed names

rwstauner 2021-05-18T17:47:31.010700Z

i'm trying to fix an issue in a dep two levels down with an externs file. i can get the extern to work if i put the file in my repo and add it to :externs but i'm trying to add it to the dep (via deps.cljs in that jar) so that other projects can get it for free... but it isn't getting picked up that way. anyone know if this does or doesn't work? versions to use? pointers on debugging?

rwstauner 2021-05-18T17:49:17.011200Z

i'd love to have shadow-cljs print out what it's passing to the compiler... if that's even how it works 🙂

rwstauner 2021-05-18T17:50:04.012Z

or does anyone know if {:externs ["file.js"]} is enough... or does it need foreign-libs to work? (from a jarred deps.cljs)

rwstauner 2021-05-18T18:53:09.014300Z

the shadow build produces a jar manifest that has the externs file contents (in "~:resources"), but the "~:externs" is just [] ... there aren't any other files in it though... it looks like it's treating it as a js module

rwstauner 2021-05-18T19:07:59.014800Z

confirmed, if i rename that file to .txt it no longer shows up in the manifest even though it's supposed to be in :externs

thheller 2021-05-18T19:44:42.015100Z

@clj149 shadow-cljs does not support externs via deps.cljs

thheller 2021-05-18T19:45:02.015500Z

and regular CLJS doesn't support the simplified .txt externs

rwstauner 2021-05-18T19:45:12.015700Z

ok, thanks

rwstauner 2021-05-18T19:45:48.016100Z

so any externs required must be in the project being built

thheller 2021-05-18T19:46:23.016700Z

yeah, libraries nowadays should really use ^js hints when needed. that works in everything and is easier to maintain.

rwstauner 2021-05-18T19:47:14.017700Z

yeah, i've confirmed that that helps, but was trying to hack around external libraries if there was any magic way to do it

rwstauner 2021-05-18T19:47:15.017900Z

thanks