Fork me on GitHub
#shadow-cljs
<
2021-05-18
>
Aron03:05:22

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

Aron03:05:30

if the target is node-test

Franklin07:05:30

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?

thheller07:05:43

@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

👍 3
Margo14:05:03

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
?

Margo14:05:04

I am trying to get a selmer workaround

thheller17:05:21

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

thheller17:05:18

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

Margo15:05:39

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

Margo15:05:47

Unless I am missing something

thheller15:05:40

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

thheller15:05:32

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

thheller15:05:54

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

Margo15:05:39

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

Margo15:05:25

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

thheller15:05:42

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

thheller15:05:01

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

Margo15:05:05

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/"]}
     }

thheller15:05:27

well there you have it 😛

thheller15:05:45

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

thheller15:05:56

that needs to match, so switch either

Margo15:05:47

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

thheller15:05:02

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

Margo15:05:17

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

thheller15:05:11

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

Margo15:05:39

thanks! Ill read into it!

thheller15:05:41

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

Margo15:05:18

that is literally what I have

Margo16:05:08

ok, actually, needed to clear cache

Margo16:05:12

now it works

👍 4
Margo16:05:22

With the paths being identical!

Margo16:05:31

Thanks a lot! Very useful tip!

rwstauner17:05:31

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?

rwstauner17:05:17

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

rwstauner17:05:04

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

rwstauner18:05:09

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

rwstauner19:05:59

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

thheller19:05:42

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

thheller19:05:02

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

rwstauner19:05:48

so any externs required must be in the project being built

thheller19:05:23

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

rwstauner19:05:14

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