-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
vite.config.ts
142 lines (129 loc) · 3.29 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
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
import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv, PluginOption, UserConfig } from "vite";
import laravel from "laravel-vite-plugin";
import vue from "@vitejs/plugin-vue";
import i18n from "laravel-vue-i18n/vite";
const laravelPlugin = laravel({
input: ["resources/sass/app.scss", "resources/js/app.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;
}
console.log(req.url);
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: [
vue({ template: { transformAssetUrls: { base: null, includeAbsolute: false } } }),
i18n(),
],
server: {
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.esm-bundler.js",
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes("node_modules")) {
return id.toString().split("node_modules/")[1].split("/")[0].toString();
}
},
},
},
},
css: {
preprocessorOptions: {
scss: {
api: "modern",
},
},
},
} as UserConfig;
/** @type {import('vite').UserConfig} */
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
const config = baseConfig;
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");
}
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/": env.VITE_HTTP_PROXY_TARGET,
};
config.plugins.push(localDevelopMiddleware);
return config;
}
}
// command === 'build'
config.plugins.push(laravelPlugin);
return config;
});