Closed dgp1130 closed 1 year ago
One downside to the second approach is that it isn't compatible with strict dependencies since it isn't evaluated until runtime when all transitive components have their scripts and styles available. The first approach is actually checked at build time with only resources known to the component. So we could perform strict deps checking on that approach, but not the second.
I was able to update to use the includeScript('./foo.mjs', import.meta)
pattern without too much effort. This introduces a few new constraints on user code:
./
or ../
).
.js
, .cjs
, .mjs
, or .css
).
package.json
file into account, but there's not much need for this when loading internal scripts or styles.Ultimately the syntax is much nicer to work with and I'm pretty happy with it. It still doesn't solve the strict deps problem, but we have #2 and #3 to look into that.
Currently
includeScript()
andinlineStyle()
require full workspace-relative paths:This is annoying and verbose, ideally we should be able to do relative paths given that 99% of the time a component's prerender logic is in the same directory as its script or style. This is also more aligned with JavaScript and
@aspect_rules_js
which tend to use relative paths for these kinds of things (the above paths would be interpreted as belonging to thepath
package in a strict Node sense).The two paths forward here are either:
This might be possible to do with a loader though that's still experimental. It would likely also require a TypeScript plugin so it understand the type of the result from the assertion.
The other path is to use
import.meta.url
like so:The given path can be evaluated relative to the URL of the source file. This seems like the most straightforward approach and the easiest to implement, so we should probably start there.