-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (59 loc) · 1.86 KB
/
vite.config.ts
File metadata and controls
61 lines (59 loc) · 1.86 KB
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
import { cloudflare } from "@cloudflare/vite-plugin";
import { reactRouter } from "@react-router/dev/vite";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig, type Plugin } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import babel from "vite-plugin-babel";
/**
* Mock globalThis.Cloudflare for pre-rendering in Node.js.
* The Cloudflare vite plugin generates code that accesses Cloudflare-specific
* APIs which don't exist in Node.js where pre-rendering runs.
*/
function mockCloudflareForPrerender(): Plugin {
return {
name: "mock-cloudflare-for-prerender",
renderChunk(code, chunk) {
if (chunk.fileName.includes("worker-entry")) {
const mock = `
if (typeof globalThis.Cloudflare === "undefined") {
globalThis.Cloudflare = {
compatibilityFlags: {
enable_nodejs_process_v2: false,
},
};
}
`;
return mock + code;
}
return null;
},
};
}
export default defineConfig(() => ({
server: {
port: 8788,
fs: {
// Restrict files that could be served by Vite's dev server. Accessing
// files outside this directory list that aren't imported from an allowed
// file will result in a 403. Both directories and files can be provided.
// If you're comfortable with Vite's dev server making any file within the
// project root available, you can remove this option. See more:
// https://vitejs.dev/config/server-options.html#server-fs-allow
allow: ["app", "node_modules/highlight.js"],
},
},
plugins: [
mockCloudflareForPrerender(),
cloudflare({ viteEnvironment: { name: "ssr" } }),
tailwindcss(),
reactRouter(),
tsconfigPaths(),
babel({
filter: /\.[jt]sx?$/,
babelConfig: {
presets: ["@babel/preset-typescript"],
plugins: [["babel-plugin-react-compiler", { target: "19" }]],
},
}),
],
}));