-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.mts
190 lines (188 loc) · 7.17 KB
/
vite.config.mts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import path from "path";
import { VitePWA } from "vite-plugin-pwa";
import { htmlInjectionPlugin } from "vite-plugin-html-injection";
const ENV_DIR = "env";
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Vite doesn't load .env until after config is resolved, so it knows where
// to look. But us humans already know, so load 'er up!
const env = loadEnv(mode, `${process.cwd()}/${ENV_DIR}`, "VITE_");
return {
define: {
"import.meta.env.BUILD_TIMESTAMP": JSON.stringify(
new Date().toISOString(),
),
// apollo client's "dev mode"
"globalThis.__DEV__": JSON.stringify(mode === "development"),
},
envDir: ENV_DIR,
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
server: {
port: 3001,
},
build: {
outDir: "build",
// When switching from CRA to Vite, the main bundle was ~550 kb, for
// both systems. Setting this slightly larger to hopefully catch any
// egregious future growth, but not warn about the status quo.
chunkSizeWarningLimit: 600,
},
plugins: [
react({
// This SWC plugin can nominally avoid the silliness in codegen
// output, where there are two non-tree-shakeable copies of each
// query in the prod bundle. But per SOP, there is no version
// compatibility matrix, and whatever we have doesn't work. Docs
// are: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#swc-plugin
// The package name: @graphql-codegen/client-preset-swc-plugin
// plugins: [
// [
// "@graphql-codegen/client-preset-swc-plugin",
// {
// artifactDirectory: "./src/__generated__/",
// gqlTagName: "gql",
// },
// ],
// ],
}),
VitePWA({
registerType: "prompt",
injectRegister: "script",
pwaAssets: {
disabled: false,
config: true,
},
manifest: {
short_name: "Food Software",
name: "Brenna's Food Software",
icons: [
{
src: "android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "any",
},
{
src: "android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
{
src: "android-chrome-384x384.png",
sizes: "384x384",
type: "image/png",
},
{
src: "android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "android-chrome-96x96.png",
sizes: "96x96",
type: "image/png",
},
],
scope: "/",
start_url: "/shop",
display: "standalone",
// equivalent to import.meta.env.VITE_THEME_COLOR
theme_color: env.VITE_THEME_COLOR,
background_color: "#1b1b1b",
shortcuts: [
{
name: "Shop",
url: "/shop",
icons: [
{
src: "shop-96x96.png",
sizes: "96x96",
},
{
src: "shop-192x192.png",
sizes: "192x192",
},
],
},
{
name: "Plan",
url: "/plan",
icons: [
{
src: "plan-96x96.png",
sizes: "96x96",
},
{
src: "plan-192x192.png",
sizes: "192x192",
},
],
},
{
short_name: "Recipes",
name: "Recipe Library",
url: "/library",
icons: [
{
src: "library-96x96.png",
sizes: "96x96",
},
{
src: "library-192x192.png",
sizes: "192x192",
},
],
},
],
},
workbox: {
globPatterns: ["**/*.{js,css,html,svg,png,ico}"],
cleanupOutdatedCaches: true,
clientsClaim: true,
},
devOptions: {
enabled: true,
navigateFallback: "index.html",
suppressWarnings: false,
type: "module",
},
}),
htmlInjectionPlugin({
injections: [
{
name: "meta prod",
path: "./src/snippets/meta.html",
type: "raw",
injectTo: "head",
buildModes: "prod",
},
{
name: "meta dev",
path: "./src/snippets/meta_dev.html",
type: "raw",
injectTo: "head",
buildModes: "dev",
},
],
}),
],
test: {
globals: true,
environment: "jsdom",
css: true,
reporters: ["verbose"],
coverage: {
reporter: ["text", "json", "html"],
include: ["src/**/*"],
exclude: [],
},
},
};
});