-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.js
More file actions
149 lines (136 loc) · 5.72 KB
/
Copy pathvite.config.js
File metadata and controls
149 lines (136 loc) · 5.72 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
import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import path, { resolve } from "path";
import Table from "cli-table3";
import chalk from "chalk";
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
// Check both .env file and process.env for compatibility with CI
const isDev = (env.IS_DEV === "true" || env.IS_DEV === true || process.env.IS_DEV === "true" || process.env.IS_DEV === true) ?? false;
const isProd = (env.IS_PROD === "true" || env.IS_PROD === true || process.env.IS_PROD === "true" || process.env.IS_PROD === true) ?? false;
// Build information table - will be updated with URL later
const buildTable = new Table({
style: {
border: ["grey"],
compact: false,
},
});
const styledMode = mode === "development" ? chalk.green("DEV") : mode === "production" ? chalk.blue("PROD") : chalk.yellow(mode);
buildTable.push([chalk.magenta("This is"), chalk.yellow(`kinda fun.`)]);
buildTable.push([chalk.magenta("Mode"), `${styledMode}`]);
return {
plugins: [
vue(),
vueDevTools(),
// Custom plugin to show homepage URL after server starts
{
name: "show-homepage-url",
configureServer(server) {
const originalListen = server.listen;
server.listen = function (...args) {
const result = originalListen.apply(this, args);
// Show URL after server is listening
setTimeout(() => {
const address = server.httpServer?.address();
if (address && typeof address === "object") {
const port = address.port;
const host = server.config.server.host === true ? "localhost" : server.config.server.host || "localhost";
// Get the full URL based on mode and configuration
let baseUrl;
if (mode === "production") {
// In production, use the actual domain
baseUrl = env.VITE_APP_URL || process.env.VITE_APP_URL || "https://kinda.fun";
} else {
// In development/preview, use the server configuration
const protocol = server.config.server.https ? "https" : "http";
baseUrl = `${protocol}://${host}:${port}`;
}
const homepageUrl = mode === "development" ? `${baseUrl}/home.html` : baseUrl;
// Add homepage URL to the existing table with proper styling
const styledUrl = chalk.underline.cyan(homepageUrl);
buildTable.push([chalk.magenta("Homepage URL"), `${styledUrl}`]);
// Display the complete table with URL (don't clear console)
console.log("\n" + buildTable.toString() + "\n");
}
}, 100);
return result;
};
},
},
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
define: {
__APP_ENV__: env.APP_ENV,
"process.env.APP_ENV": JSON.stringify(env.APP_ENV),
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
quietDeps: true,
silenceDeprecations: ["import", "global-builtin", "color-functions"],
},
},
},
build: {
rollupOptions: {
input: {
cameo: resolve(__dirname, "src/entries/cameo.js"),
court: resolve(__dirname, "src/entries/court.js"),
guillotine: resolve(__dirname, "src/entries/guillotine.js"),
invalid: resolve(__dirname, "src/entries/invalid.js"),
meeting: resolve(__dirname, "src/entries/meeting.js"),
pretend: resolve(__dirname, "src/entries/pretend.js"),
sisyphus: resolve(__dirname, "src/entries/sisyphus.js"),
stats: resolve(__dirname, "src/entries/stats.js"),
wrongest: resolve(__dirname, "src/entries/wrongest.js"),
home: resolve(__dirname, "src/entries/home.js"),
404: resolve(__dirname, "src/entries/404.js"),
megachurch: resolve(__dirname, "src/entries/megachurch.js"),
},
output: {
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
assetFileNames: "[name][extname]",
},
},
},
server: {
middlewareMode: false,
host: true,
configureServer(server) {
server.middlewares.use((req, res, next) => {
// Only rewrite for root-level slugs (e.g., /cameo, /guillotine, etc.)
const mpaPages = ["cameo", "court", "guillotine", "invalid", "meeting", "megachurch", "pretend", "sisyphus", "stats", "wrongest", "home", "404"];
const url = req.url.split("?")[0];
console.log("Middleware hit for URL:", url);
// If the URL is exactly "/", rewrite to /home.html
if (url === "/") {
req.url = "/home.html";
console.log("Rewrite / to /home.html");
} else {
// If the URL is exactly "/slug", rewrite to "/slug.html"
const match = url.match(/^\/(\w+)\/?$/);
if (match && mpaPages.includes(match[1])) {
req.url = `/${match[1]}.html`;
console.log(`Rewrite ${url} to ${req.url}`);
} else {
// For any unmatched routes that look like pages (not assets), serve the 404 page
if (!url.includes(".") && url !== "/" && !url.startsWith("/@") && !url.startsWith("/node_modules")) {
req.url = "/404.html";
console.log(`Rewrite ${url} to /404.html (404 case)`);
}
}
}
next();
});
},
},
};
});