generated from forge42dev/open-source-stack
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
react-router.config.ts
37 lines (36 loc) · 1.09 KB
/
react-router.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fs from "node:fs";
import type { Config } from "@react-router/dev/config";
import esbuild from "esbuild";
export default {
buildEnd: async ({ reactRouterConfig }) => {
const sentryInstrument = `instrument.server`;
await esbuild
.build({
alias: {
"~": `./app`,
},
outdir: `${reactRouterConfig.buildDirectory}/server`,
entryPoints: [`./app/server/${sentryInstrument}.ts`],
platform: "node",
format: "esm",
// Don't include node_modules in the bundle
packages: "external",
bundle: true,
logLevel: "info",
})
.then(() => {
const serverBuildPath = `${reactRouterConfig.buildDirectory}/server/${reactRouterConfig.serverBuildFile}`;
fs.writeFileSync(
serverBuildPath,
Buffer.concat([
Buffer.from(`import "./${sentryInstrument}.js"\n`),
Buffer.from(fs.readFileSync(serverBuildPath)),
])
);
})
.catch((error: unknown) => {
console.error(error);
process.exit(1);
});
},
} satisfies Config;