Is there some way to make shadow-cljs emit a raw import? Webpack can't seem to find imports wrapped in shadow.esm.dynamic_import. Do I need to add a post-processing hook to hard-replace shadow.esm.dynamic_import > import in the output files?
(:require ["whatever" ...]) is a raw import, otherwise no not really
I'd still need it to be a dynamic import for code splitting
the shadow.esm.dynamic_import is working around the closure compiler otherwise complaining about import() and bailing
so this is basically just hiding it from that, so if you were to add it via other means you'd just have to fight that again
haven't found a good alternative that closure is happy with
i was thinking of just post-processing the shadow-cljs output files with awk and replace all instances of shadow.esm.dynamic_import
you could try that
could i do something like that in a build hook?
I suppose so yeah
in the :optimize-finish stage you'll find the compiled modules under :shadow.build.closure/modules. its a vector. each entry will have an :output key which is the generated JS
however modifying this in any way is very likely to break the source maps
and it'll only work for release builds. dev builds look different and don't have that.
i haven't tested the release build in operation, but in dev it worked
first i made an exported thing like (def ^:export dynamic-import shadow.esm/dynamic-import) (since shadow.esm/dynamic-import isn't ^:export so it gets munged)
in dev i just replaced all instances of my_ns.dynamic_import with import. this worked.
in prd i first tried to find its new name which ends up in some $APP.foo("my_ns.dynamic_export",AB) kinda call. its invocations all looked like AB.c?AB.c("imported thing"):AB.call(null,"imported thing"). i replaced all these with import("imported thing") but haven't had time to test yet.
at least webpack doesn't complain about it and code splitting works
I was wondering if the "closure doesn't allow import()" is still a problem if I target es2020+?
its completely irrelevant to that. its a build thing. just like webpack the closure compiler will interpret import("./something.js") and try to actually process and bundle it. there is currently no option to tell it to ignore those
well technically there is an option, but it comes with a bunch of constraints and doesn't actually work 😛
oh 😞