Fork me on GitHub
#shadow-cljs
<
2020-11-12
>
bendy12:11:11

Hey all - I'm in the process of code splitting our single file js into multiple modules. Using the loader works on the home page, as loader/load "module" fetches /js/module.js, however if I load any other page (say /foo/bar) loader/load "module" tries to fetch /foo/js/module.js. How can I ensure that the asset path remains consistent regardless of the url?

thheller12:11:58

set the correct :asset-path "/js" in your build config. looks like you have :asset-path "js"?

bendy12:11:37

:man-facepalming:

bendy12:11:45

doh, you are correct, thanks!

jkent14:11:19

Can I tell shadow to watch certain npm dependencies? I’ve used yarn link to create a symlink between my cljs project and a js library but shadow is not picking up the new changes to the js library when it recompiles

thheller14:11:25

shadow no longer watches any npm dependencies since that was causing issues on some projects

thheller14:11:40

you can touch the package.json of the package to trigger a recompile though

thheller14:11:10

so if you do that after building the js lib it should work out

jkent14:11:11

@thheller thanks! thats works and it much better than restarting shadow 🙂

darwin16:11:11

@thheller just a follow up, thanks for your insigths, I was able to work around the dynamic import issue by forking the repo and turning it into static import[1], luckily that was the only instance of dynamic import in my npm deps. By looking around I noticed PR[2] in closure compiler, so I guess a support for dynamic imports is imminent upstream [1] https://github.com/darwin/use-cannon/commit/81fb03fda4aaf31b60085ece9118cb02183fce74 [2] https://github.com/google/closure-compiler/pull/3706

thheller17:11:13

nah not really. it'll most likely just be ignored. https://github.com/google/closure-compiler/issues/3707

thheller17:11:25

I also think it should NOT be supported. it is sort of annoying if libraries do this because they enforce code splitting on you in places where it might not actually make sense for your app.

thheller17:11:02

sure there needs to be a way to do conditional code loading somehow but this is just one of the latest hacks in this area ...

darwin17:11:26

I’d like to open an issue with use-cannon and persuade them not to use dynamic imports so I could eventually return to their official version.

darwin17:11:30

Not sure if I have good arguments though, I’m not familiar with this new JS stuff.

thheller17:11:06

well I don't really know why they are doing this so I can't say either

thheller17:11:41

from the looks of it they do it to only conditionally load the Provider stuff when in a context with window

thheller17:11:52

so presumably the code can also be loaded in a worker where they don't want that code

thheller17:11:05

but I don't get why there is import { ProviderProps } from './Provider' and then import('./Provider')

thheller17:11:44

so I don't really understand what this code is even supposed to do from the bundler perspective

darwin17:11:25

I was also wondering about that repeated ./Provider import, once static, second time dynamic, also that was causing warnings about cyclic dependencies when I was trying to compile the dist files of the package on my machine, because provider imports index again. Anyways, thanks for your points, I will ask them in an issue.

thheller17:11:30

I'd expect webpack do duplicate content but no clue why anyone would want that

thheller17:11:00

would be interesting to see what webpack actually does

thheller17:11:12

hmm looks like the ProviderProps is just a type so probably a misplaced import that should be in the import type further up

thheller17:11:34

maybe the typescript compiler removes that import later so it never gets to webpack

darwin17:11:04

fyi, if you wanted to follow this up, please subscribe this issue: https://github.com/pmndrs/use-cannon/issues/132