Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
155 lines (148 loc) · 5.68 KB
/
Copy pathvite.config.ts
File metadata and controls
155 lines (148 loc) · 5.68 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
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
import { sentryReactRouter } from "@sentry/react-router/vite";
import { prismaVitePlugin } from "@prisma/orm-postgres/vite-plugin-contract-emit";
import { resolve } from "node:path";
import { reactRouter } from "@react-router/dev/vite";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite-plus";
export default defineConfig((config) => {
// Expose the deploy's commit SHA to the client bundle so client events are
// tagged with the same release the sourcemaps were uploaded to.
process.env.VITE_SENTRY_RELEASE ??= process.env.VERCEL_GIT_COMMIT_SHA ?? "";
return {
staged: {
"*": "vp check --fix",
},
fmt: {
ignorePatterns: [
".react-router/**",
"build/**",
"node_modules/**",
"data-test/**",
"test/fixtures/**",
// Emitted by scripts/build-warranty-policies.ts: mechanical, and
// reformatting it would churn against the generator's own output.
"app/data/warranty-policies.ts",
// Emitted by `prisma contract emit`: same story. Formatting these
// churns thousands of lines against what the generator writes, and
// the next emit undoes it.
"prisma/contract.d.ts",
"prisma/contract.json",
// Agent skill bundles written by `prisma skills sync` on install.
".agents/**",
".claude/**",
".cursor/**",
".devin/**",
],
printWidth: 80,
tabWidth: 2,
singleQuote: false,
semi: true,
},
lint: {
ignorePatterns: [
".react-router/**",
"build/**",
"node_modules/**",
"data-test/**",
"test/fixtures/**",
// tsgolint overflows on vite config generics; tsc checks it cleanly.
"vite.config.ts",
// Generated contract snapshots, one per storage hash. They pin the
// orm package's export paths at the time each was written, so after
// an @prisma/orm-* bump old snapshots reference subpaths that no
// longer exist; tsconfig keeps them out of tsc's program entirely.
"migrations/**",
// Emitted contract files: generated, never hand-edited (see fmt).
"prisma/contract.d.ts",
"prisma/contract.json",
// Generated agent skill bundles (see fmt).
".agents/**",
".claude/**",
".cursor/**",
".devin/**",
],
options: {
reportUnusedDisableDirectives: "warn",
typeAware: true,
typeCheck: true,
},
rules: {
"no-console": ["error", { allow: ["assert", "error", "info", "warn"] }],
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
"react/no-danger": "error",
"typescript/no-explicit-any": "warn",
"typescript/no-unsafe-declaration-merging": "error",
"unicorn/no-array-for-each": "warn",
"unicorn/prefer-array-flat-map": "error",
},
},
plugins: [
tailwindcss(),
reactRouter(),
// Re-emit prisma/contract.json + contract.d.ts when the contract
// changes in dev, so a save doesn't leave the dev server running on
// stale artifacts. Dev only: production emits through prebuild, and a
// test run emits through `pnpm test`'s build (and `pnpm check`). Skipping
// it under vitest also avoids the config's module graph being loaded by
// the test runner: that graph reaches `pg`, a CJS package the runner
// evaluates without a `require`, so every run logged a failed config
// graph root before emitting anyway.
...(process.env.VITEST ? [] : [prismaVitePlugin("prisma.config.ts")]),
// Sentry's release + sourcemap push belongs to production deploys: the
// plugin injects the sentryConfig the buildEnd hook reads, then pushes
// in its writeBundle pass. Local and CI builds skip it entirely, and
// the buildEnd hook in react-router.config.ts skips with them, so a
// missing or placeholder SENTRY_AUTH_TOKEN cannot produce build noise.
...(process.env.VERCEL_ENV === "production"
? [
sentryReactRouter(
{
org: "labnotes",
project: "expense",
authToken: process.env.SENTRY_AUTH_TOKEN,
telemetry: false,
// Release name for sourcemaps + release health. Vercel provides
// the commit SHA at build time; SENTRY_RELEASE overrides if ever
// needed. (The react-router wrapper forwards a release OBJECT; a
// bare string gets spread into char indices and the name is
// silently lost.)
release: {
name:
process.env.SENTRY_RELEASE ??
process.env.VERCEL_GIT_COMMIT_SHA,
},
},
config,
),
]
: []),
],
resolve: {
alias: [
{ find: "~", replacement: resolve("app") },
{ find: "~/test", replacement: resolve("test") },
{ find: "+types", replacement: resolve(".react-router/types") },
],
},
test: {
projects: ["./vitest.unit.config.ts", "./vitest.main.config.ts"],
},
optimizeDeps: {
// Never pre-bundle Node-only/native packages: the client never imports
// them (server code is stripped from route bundles), and rolldown-vite's
// optimizer chokes on their .node binaries (UNLOADABLE_DEPENDENCY).
exclude: [
"@sentry/react-router",
"@napi-rs/canvas",
"@resvg/resvg-js",
"sharp",
"tesseract.js",
"pdfjs-dist",
"@sparticuz/chromium",
"puppeteer-core",
"@sentry/profiling-node",
],
},
};
});