read out entry file path from manifest file

This commit is contained in:
Hans Pagel committed 2023-01-23 16:36:40 +01:00
1 parent 5d743ff018
commit 834c46a095
3 files changed
+46 -12

No files matched your search

+17 -1
View File
@@ -10,6 +10,7 @@ import documentLoader from "@server/commands/documentLoader";
import env from "@server/env";
import { Integration } from "@server/models";
import presentEnv from "@server/presenters/env";
import manifest from "@server/utils/manifest";
import { getTeamFromContext } from "@server/utils/passport";
import prefetchTags from "@server/utils/prefetchTags";
@@ -68,6 +69,20 @@ export const renderApp = async (
const environment = `
window.env = ${JSON.stringify(presentEnv(env, options.analytics))};
`;
const entry = "app/index.tsx";
const scriptTags = isProduction
? `<script type="module" src="/${manifest[entry]["file"]}"></script>`
: `<script type="module">
import RefreshRuntime from 'http://localhost:3001/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => { }
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
<script type="module" src="http://localhost:3001/@vite/client"></script>
<script type="module" src="http://localhost:3001/${entry}"></script>
`;
ctx.body = page
.toString()
.replace(/\/\/inject-env\/\//g, environment)
@@ -75,7 +90,8 @@ export const renderApp = async (
.replace(/\/\/inject-description\/\//g, escape(description))
.replace(/\/\/inject-canonical\/\//g, canonical)
.replace(/\/\/inject-prefetch\/\//g, shareId ? "" : prefetchTags)
.replace(/\/\/inject-slack-app-id\/\//g, env.SLACK_APP_ID || "");
.replace(/\/\/inject-slack-app-id\/\//g, env.SLACK_APP_ID || "")
.replace(/\/\/inject-script-tags\/\//g, scriptTags);
};
export const renderShare = async (ctx: Context, next: Next) => {
+1 -11
View File
@@ -70,16 +70,6 @@
.setAttribute("content", color);
}
</script>
<!-- if development -->
<script type="module">
import RefreshRuntime from 'http://localhost:3001/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => { }
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
<script type="module" src="http://localhost:3001/@vite/client"></script>
<script type="module" src="http://localhost:3001/app/index.tsx"></script>
<!-- TODO: Production?-->
//inject-script-tags//
</body>
</html>
+28
View File
@@ -0,0 +1,28 @@
import fs from "fs";
import path from "path";
type ManifestFile = Record<
string,
{
file: string;
src: string;
isEntry?: boolean;
}
>;
const file = path.resolve("./build/app/manifest.json");
let manifest;
try {
manifest = fs.readFileSync(file, "utf8");
manifest = JSON.parse(manifest);
} catch (err) {
console.warn(
`Can not find ${file}. Try executing "yarn vite:build" before running in production mode.`
);
manifest = {};
}
export default manifest as ManifestFile;