-
Notifications
You must be signed in to change notification settings - Fork 174
/
vite.config.ts
110 lines (105 loc) · 2.87 KB
/
vite.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { devServer } from "react-router-hono-server/dev";
import esbuild from "esbuild";
import { flatRoutes } from "remix-flat-routes";
import { cjsInterop } from "vite-plugin-cjs-interop";
import { init } from "@paralleldrive/cuid2";
import fs from "node:fs";
const createHash = init({
length: 8,
});
const buildHash = process.env.BUILD_HASH || createHash();
export default defineConfig({
server: {
port: 3000,
// https: {
// key: "./server/dev/key.pem",
// cert: "./server/dev/cert.pem",
// },
warmup: {
clientFiles: [
"./app/entry.client.tsx",
"./app/root.tsx",
"./app/routes/**/*",
],
},
},
optimizeDeps: {
include: ["./app/routes/**/*"],
},
build: {
target: "ES2022",
assetsDir: `file-assets`,
rollupOptions: {
output: {
entryFileNames: `file-assets/${buildHash}/[name]-[hash].js`,
chunkFileNames() {
return `file-assets/${buildHash}/[name]-[hash].js`;
},
assetFileNames() {
return `file-assets/${buildHash}/[name][extname]`;
},
},
},
},
resolve: {
alias: {
".prisma/client/index-browser":
"./node_modules/.prisma/client/index-browser.js",
},
},
plugins: [
cjsInterop({
// List of CJS dependencies that require interop
dependencies: [
"react-microsoft-clarity",
"@markdoc/markdoc",
"react-to-print",
],
}),
devServer(),
remix({
ignoredRouteFiles: ["**/.*"],
future: {
// unstable_optimizeDeps: true,
},
routes: async (defineRoutes) => {
return flatRoutes("routes", defineRoutes);
},
buildEnd: async ({ remixConfig }) => {
const sentryInstrument = `instrument.server`;
await esbuild
.build({
alias: {
"~": `./app`,
},
outdir: `${remixConfig.buildDirectory}/server`,
entryPoints: [`./server/${sentryInstrument}.ts`],
platform: "node",
format: "esm",
// Don't include node_modules in the bundle
packages: "external",
bundle: true,
logLevel: "info",
})
.then(() => {
const serverBuildPath = `${remixConfig.buildDirectory}/server/${remixConfig.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);
});
},
}),
tsconfigPaths(),
],
});