Inlining specific JS files into HTML when the JS files are content hashes? #12283
Unanswered
sbhbenjamin
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Hello everyone!
I’m trying to inline a small JS file using
output.inlineScripts, and I’m a bit stuck on how to reliably target it once filenames are fully hashed.From the docs, I understand that we can use
output.inlineScriptswith a RegExp or a function, e.g.:This works fine as long as the emitted filename still contains the entry name (e.g.
resource/js/webapp-inline.809d8882.js).However, when I configure my build so that most JS files are emitted as hash-only filenames (e.g.
resource/js/623bbadf790b6998.js), only the main entry keeps a readable name, and the extra entry I want to inline (webapp-inline) no longer haswebapp-inlinein the final filename. At that point, myinlineScriptsregex can’t “see” it anymore, since the{ name }passed toinlineScriptsis just the hashed filename.What I have tried
Based on this discussion:
web-infra-dev/rsbuild#2290
I tried adding a separate entry and using
dependOn:But with this setup the
webapp-inlinechunk isn't present as part of the dependencies for home/index.html, so it can't be inlined.Question
My questions:
webapp-inline) when filenames are fully hashed?inlineScriptsto know which entry a file belongs to (e.g. viaentryNameor chunk info), or should I instead be usinghtml.templateParameters/@rspack/plugin-htmlto look up assets by entry name and inline them from the HTML template?Any guidance or examples for this scenario would be greatly appreciated. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions