diff --git a/packages/core/src/compiler/htmlBundler.test.ts b/packages/core/src/compiler/htmlBundler.test.ts
index 724ad9bfa..195d133e0 100644
--- a/packages/core/src/compiler/htmlBundler.test.ts
+++ b/packages/core/src/compiler/htmlBundler.test.ts
@@ -250,6 +250,43 @@ describe("bundleToSingleHtml", () => {
expect(hostEl?.hasAttribute("data-composition-src")).toBe(false);
});
+ it("inlines local scripts referenced by sub-compositions into the bundle", async () => {
+ const dir = makeTempProject({
+ "index.html": `
+
+
+
+
+
+`,
+ "compositions/scene.html": `
+
+`,
+ "shared/dist/vendor/powerglitch.min.js": `window.PowerGlitch = { glitch(){ return { startGlitch(){}, stopGlitch(){} }; } };`,
+ "shared/dist/index.js": `window.__HF_SHARED_TEST__ = "shared-runtime-loaded";`,
+ });
+
+ const bundled = await bundleToSingleHtml(dir);
+
+ expect(bundled).toContain('__HF_SHARED_TEST__ = "shared-runtime-loaded"');
+ expect(bundled).toContain("window.PowerGlitch = { glitch()");
+ expect(bundled).not.toContain('src="shared/dist/index.js"');
+ expect(bundled).not.toContain('src="shared/dist/vendor/powerglitch.min.js"');
+ });
+
it("does not duplicate CDN scripts already present in the main document", async () => {
const dir = makeTempProject({
"index.html": `
diff --git a/packages/core/src/compiler/htmlBundler.ts b/packages/core/src/compiler/htmlBundler.ts
index 6b634b2bb..69debaca2 100644
--- a/packages/core/src/compiler/htmlBundler.ts
+++ b/packages/core/src/compiler/htmlBundler.ts
@@ -840,6 +840,14 @@ export async function bundleToSingleHtml(
// Inject external scripts from sub-compositions (e.g., Lottie CDN)
// that aren't already present in the main document.
for (const extSrc of compExternalScriptSrcs) {
+ if (isRelativeUrl(extSrc)) {
+ const jsPath = safePath(projectDir, extSrc);
+ const js = jsPath ? safeReadFile(jsPath) : null;
+ if (js != null) {
+ compScriptChunks.push(js);
+ continue;
+ }
+ }
if (!document.querySelector(`script[src="${extSrc}"]`)) {
const extScript = document.createElement("script");
extScript.setAttribute("src", extSrc);