-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
100 lines (88 loc) · 3.51 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
import process from "node:process";
import react from "@vitejs/plugin-react";
import ssr from "vike/plugin";
import { defineConfig, loadEnv } from "vite";
import faviconsPlugin from "@anolilab/unplugin-favicons/vite";
import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
import svgr from "vite-plugin-svgr";
import { imagetools, OutputFormat } from "vite-imagetools";
export default defineConfig(async ({ mode }) => {
let url = "http://0.0.0.0:3000";
if (process.env["NETLIFY"]) {
if (process.env["CONTEXT"] === "production") {
url = process.env["URL"] as string;
} else if (process.env["CONTEXT"] !== "production") {
url = process.env["DEPLOY_PRIME_URL"] as string;
}
}
process.env["VITE_DOMAIN_URL"] = url.replace(/\/$/u, "");
Object.assign(process.env, loadEnv(mode, process.cwd()));
return {
clearScreen: false,
optimizeDeps: { include: ["react/jsx-runtime"] },
plugins: [
react({
jsxRuntime: "automatic",
}),
svgr(),
imagetools({
extendOutputFormats(builtins) {
const jsx: OutputFormat = () => (metadatas) => {
const srcSet = metadatas.map((meta) => `${meta["src"]} ${meta["width"]}w`).join(", ");
let largestImage: any;
let largestImageSize = 0;
for (let i = 0; i < metadatas.length; i++) {
const m = metadatas[i] as any;
if (m.width > largestImageSize) {
largestImage = m;
largestImageSize = m.width;
}
}
return {
srcSet,
src: largestImage === null || largestImage === void 0 ? void 0 : largestImage.src,
width: largestImage === null || largestImage === void 0 ? void 0 : largestImage.width,
height: largestImage === null || largestImage === void 0 ? void 0 : largestImage.height,
};
};
return {
...builtins,
jsx,
};
},
defaultDirectives: (url) => {
if (url.searchParams.has("jsx")) {
const { jsx, ...params } = Object.fromEntries(url.searchParams.entries());
return new URLSearchParams({
format: "webp",
quality: "75",
w: "200;400;600;800;1200",
withoutEnlargement: "",
...params,
as: "jsx",
});
}
return new URLSearchParams();
},
}),
faviconsPlugin({
logo: "./assets/logo.svg",
outputPath: "assets",
}),
ssr({
prerender: {
noExtraDir: true,
parallel: 1, // Can be `number` or `boolean`
partial: false,
},
}),
ViteImageOptimizer({}),
],
ssr: {
noExternal: ["react-helmet-async"],
},
test: {
environment: "node",
},
};
});