Skip to content

🎥 Make videos programmatically with React

`@remotion/bundler`: Fix 404 for sourcemap and favicon when deploying site to lambda

Jonny Burger94067f2111f3
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.ts
index bd1fcc747e..028892c141 100644
--- a/packages/bundler/src/bundle.ts
+++ b/packages/bundler/src/bundle.ts
@@ -227,10 +227,10 @@ export const internalBundle = async (
throw new Error(errors[0].message + '\n' + errors[0].details);
}
- const baseDir = actualArgs?.publicPath ?? '/';
+ const publicPath = actualArgs?.publicPath ?? '/';
const staticHash =
'/' +
- [trimTrailingSlash(trimLeadingSlash(baseDir)), 'public']
+ [trimTrailingSlash(trimLeadingSlash(publicPath)), 'public']
.filter(Boolean)
.join('/');
@@ -270,7 +270,7 @@ export const internalBundle = async (
const html = indexHtml({
staticHash,
- baseDir,
+ publicPath,
editorName: null,
inputProps: null,
remotionRoot: resolvedRemotionRoot,
@@ -288,10 +288,10 @@ export const internalBundle = async (
name: f.name.split(path.sep).join('/'),
};
}),
- includeFavicon: false,
+ includeFavicon: true,
title: 'Remotion Bundle',
renderDefaults: undefined,
- publicFolderExists: `${baseDir + (baseDir.endsWith('/') ? '' : '/')}public`,
+ publicFolderExists: `${publicPath + (publicPath.endsWith('/') ? '' : '/')}public`,
gitSource: actualArgs.gitSource ?? null,
projectName: getProjectName({
gitSource: actualArgs.gitSource ?? null,
diff --git a/packages/bundler/src/index-html.ts b/packages/bundler/src/index-html.ts
index b5eb5c2464..98dbd08142 100644
--- a/packages/bundler/src/index-html.ts
+++ b/packages/bundler/src/index-html.ts
@@ -3,7 +3,7 @@ import type {StaticFile} from 'remotion';
import {Internals} from 'remotion';
export const indexHtml = ({
- baseDir,
+ publicPath,
editorName,
inputProps,
envVariables,
@@ -21,7 +21,7 @@ export const indexHtml = ({
projectName,
}: {
staticHash: string;
- baseDir: string;
+ publicPath: string;
editorName: string | null;
inputProps: object | null;
envVariables?: Record<string, string>;
@@ -47,7 +47,7 @@ export const indexHtml = ({
<link rel="preconnect" href="https://fonts.gstatic.com" />
${
includeFavicon
- ? `<link id="__remotion_favicon" rel="icon" type="image/png" href="/remotion.png" />`
+ ? `<link id="__remotion_favicon" rel="icon" type="image/png" href="${publicPath}favicon.ico" />`
: ''
}
<title>${title}</title>
@@ -61,6 +61,7 @@ export const indexHtml = ({
: '<script>window.remotion_editorName = null;</script>'
}
<script>window.remotion_projectName = ${JSON.stringify(projectName)};</script>
+ <script>window.remotion_publicPath = ${JSON.stringify(publicPath)};</script>
<script>window.remotion_renderDefaults = ${JSON.stringify(
renderDefaults,
)};</script>
@@ -111,7 +112,7 @@ export const indexHtml = ({
<div id="menuportal-5"></div>
<div id="remotion-error-overlay"></div>
<div id="server-disconnected-overlay"></div>
- <script src="${baseDir}bundle.js"></script>
+ <script src="${publicPath}bundle.js"></script>
</body>
</html>
`.trim();
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index dcf676e449..4cf22baa70 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -34,6 +34,7 @@ declare global {
remotion_setBundleMode: (bundleMode: BundleState) => void;
remotion_staticBase: string;
remotion_staticFiles: StaticFile[];
+ remotion_publicPath: string;
remotion_publicFolderExists: string | null;
remotion_editorName: string | null;
remotion_numberOfAudioTags: number;
diff --git a/packages/studio-server/src/routes.ts b/packages/studio-server/src/routes.ts
index 26d5269f1b..ac406a9f1a 100644
--- a/packages/studio-server/src/routes.ts
+++ b/packages/studio-server/src/routes.ts
@@ -77,7 +77,7 @@ const handleFallback = async ({
response.end(
BundlerInternals.indexHtml({
staticHash: hash,
- baseDir: '/',
+ publicPath: '/',
editorName: displayName,
envVariables: getEnvVariables(),
inputProps: getCurrentInputProps(),
@@ -355,7 +355,7 @@ export const handleRoutes = ({
}
}
- if (url.pathname === '/remotion.png') {
+ if (url.pathname === '/favicon.ico') {
return handleFavicon(request, response);
}
diff --git a/packages/studio/src/components/Notifications/ServerDisconnected.tsx b/packages/studio/src/components/Notifications/ServerDisconnected.tsx
index 5e8b2f892e..0d8c71e70c 100644
--- a/packages/studio/src/components/Notifications/ServerDisconnected.tsx
+++ b/packages/studio/src/components/Notifications/ServerDisconnected.tsx
@@ -42,7 +42,7 @@ export const ServerDisconnected: React.FC = () => {
const fav = document.getElementById('__remotion_favicon') as HTMLLinkElement;
if (ctx.type !== 'disconnected') {
- fav.setAttribute('href', '/remotion.png');
+ fav.setAttribute('href', '/favicon.ico');
return null;
}
diff --git a/packages/studio/src/components/Timeline/TimelineStack/index.tsx b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
index da0137971f..06f163f5a2 100644
--- a/packages/studio/src/components/Timeline/TimelineStack/index.tsx
+++ b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
@@ -28,7 +28,7 @@ import {getOriginalSourceAttribution} from './source-attribution';
// @ts-expect-error
SourceMapConsumer.initialize({
- 'lib/mappings.wasm': SOURCE_MAP_ENDPOINT,
+ 'lib/mappings.wasm': window.remotion_publicPath + SOURCE_MAP_ENDPOINT,
});
export const TimelineStack: React.FC<{