-
-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathvite.config.ts
More file actions
239 lines (221 loc) · 7.24 KB
/
Copy pathvite.config.ts
File metadata and controls
239 lines (221 loc) · 7.24 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import { fileURLToPath, URL } from "node:url";
import { ConfigEnv, defineConfig, HttpProxy, loadEnv, PluginOption, ProxyOptions, UserConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue";
import i18n from "laravel-vue-i18n/vite";
import tailwindcss from "@tailwindcss/vite";
import ui from "@nuxt/ui/vite";
import type { Plugin } from 'vite';
function leafletGlobalPlugin(): Plugin {
const LEAFLET_PLUGINS = [
'leaflet-gpx',
'leaflet-rotatedmarker',
'leaflet.markercluster',
];
return {
name: 'vite-plugin-leaflet-global',
transform(code, id) {
if (
LEAFLET_PLUGINS.some((p) => id.includes(p)) &&
!id.endsWith('.css') &&
!id.includes('?vue&type=style')
) {
return { code: `import L from 'leaflet';\n${code}`, map: null };
}
},
};
}
const laravelPlugin = laravel({
input: ["resources/sass/app.css", "resources/js/app.ts", "resources/sass/app-v8.css", "resources/js/app-v8.ts"],
refresh: true,
});
const localDevelopMiddleware: PluginOption = {
name: "develop-rewrite-middleware",
configureServer(server) {
const viteIndexPath = "/vite/index.html";
server.middlewares.use((req, res, next) => {
if (!req.url) {
next();
return;
}
const requestUrl : string = req.url;
const doNotTouch = ["/@", "/api", "/resources", "/node_modules"];
if (doNotTouch.some((page) => requestUrl.startsWith(page))) {
next();
return;
}
const startsWithPages = ["/gallery", "/frame", "/map", "/search"];
// Check if req.url starts with pages
if (startsWithPages.some((page) => requestUrl.startsWith(page))) {
req.url = viteIndexPath;
}
const pages = [
"/",
"/diagnostics",
"/permissions",
"/jobs",
"/maintenance",
"/profile",
"/settings",
"/sharing",
"/statistics",
"/users",
];
// Check if requestUrl is in pages
if (pages.includes(requestUrl)) {
req.url = viteIndexPath;
}
next();
});
},
}
const baseConfig = {
base: "./",
plugins: [
leafletGlobalPlugin(),
tailwindcss(),
// Declares intent (component logic reads this appConfig in places), but the
// actual --ui-color-* CSS custom properties are populated at runtime by
// resources/js/v8/theme.ts - this plugin option alone does not materialize
// them in Vue-standalone mode. See Feature 049 T-049-02.
ui({
ui: {
colors: { primary: "sky", neutral: "slate" },
card: { variants: { variant: { outline: { root: "ring-0" } } } },
// Nuxt UI's `text-inverted` flips to a dark neutral in dark mode (so
// solid buttons stay readable on the lighter shade-400 background it
// picks for dark mode) - Lychee always wants white text on the primary
// solid button regardless of color scheme.
button: { compoundVariants: [{ color: "primary", variant: "solid", class: "text-white" }] },
},
}),
vue({ template: { transformAssetUrls: { base: null, includeAbsolute: false } } }),
i18n(),
],
server: {
// cors: true, // Worst case scenario
watch: {
ignored: [
"**/.*/**",
"**/app/**",
"**/database/**",
"**/node_modules/**",
"**/public/**",
"**/storage/**",
"**/tests/**",
"**/vendor/**",
"**/presets/**",
],
},
},
resolve: {
alias: {
// @ts-ignore-next-line
"@": fileURLToPath(new URL("./resources/js/", import.meta.url)),
vue: "vue/dist/vue.runtime.esm-bundler.js",
},
},
optimizeDeps: {
// @primeuix/themes/types/* and primevue/* subpaths (imported by v7 for
// DesignTokens/MenuItem types, some via inline `import { type X } from ...`)
// only expose a `types` export condition, no runtime `import` condition. With
// two Vite entries (app.ts + app-v8.ts) sharing one dependency scan, the
// optimizer now eagerly resolves those paths and fails. `npm run build` is
// unaffected (native ESM resolution handles them fine at request time) -
// this only skips the dev-server pre-bundling scan for them.
exclude: ["@primeuix/themes", "primevue"],
},
build: {
rollupOptions: {
// @vueuse/core ships /* #__PURE__ */ comments in positions Rolldown's
// stricter checker rejects (harmless - just a missed tree-shaking hint),
// spamming the build output with INVALID_ANNOTATION warnings we can't fix upstream.
onwarn(warning, warn) {
if (warning.code === "INVALID_ANNOTATION" && warning.id?.includes("@vueuse/core")) {
return;
}
warn(warning);
},
output: {
// Per-package chunking (rather than a manual named group keyed on a
// path regex) - with two entries now sharing this build, a regex-based
// group can end up co-locating shared vendor code (e.g. vue's own
// runtime helpers) inside a chunk named after one entry's dependency,
// which then gets pulled into the OTHER entry too. Splitting strictly
// by node_modules package name keeps every dependency - PrimeVue
// included - in its own chunk, so app-v8 never references it.
manualChunks(id) {
if (id.includes("node_modules")) {
return id.toString().split("node_modules/")[1].split("/")[0].toString();
}
},
},
},
},
} as UserConfig;
function getCorsSettings(env: Record<string, string>) {
return {
"origin": env.APP_URL ?? 'http://localhost',
"methods": "GET",
"preflightContinue": false,
"optionsSuccessStatus": 204
};
}
/** @type {import('vite').UserConfig} */
export default defineConfig(({ command, mode, isSsrBuild, isPreview } : ConfigEnv) : UserConfig => {
const config = { ...baseConfig };
if (mode === 'development') {
console.log("DEVELOPMENT MODE detected");
config.build.sourcemap = true;
config.build.minify = false; // Ensure no minification in development
config.define = {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: true,
};
}
const env = loadEnv(mode, process.cwd(), "");
if (config.server === undefined) {
throw new Error("server config is missing");
}
if (config.plugins === undefined) {
throw new Error("plugins list is missing");
}
config.server.cors = getCorsSettings(env);
if (command === "serve") {
console.log("LOCAL VITE MODE detected");
if (env.VITE_HTTP_PROXY_TARGET !== undefined) {
console.log("api calls will be forwarded to:");
console.log(env.VITE_HTTP_PROXY_TARGET);
}
if (env.VITE_LOCAL_DEV === "true") {
if (env.VITE_HTTP_PROXY_TARGET === undefined) {
throw new Error("VITE_HTTP_PROXY_TARGET is missing");
}
config.server.open = "vite/index.html";
config.server.proxy = {
"/api/": {
target: env.VITE_HTTP_PROXY_TARGET,
changeOrigin: true,
secure: true,
ws: true,
configure: (proxy: HttpProxy.Server, _options: ProxyOptions) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log(req.method?.padEnd(4), '=> ', proxyReq.host + req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log(proxyRes.statusCode?.toString().padEnd(4), '<=', req.url);
});
},
}
};
config.plugins.push(localDevelopMiddleware);
return config;
}
}
// command === 'build'
config.plugins.push(laravelPlugin);
return config;
});