-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
62 lines (58 loc) · 1.4 KB
/
vite.config.ts
File metadata and controls
62 lines (58 loc) · 1.4 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
import path from "node:path";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";
import { promises as fs } from "node:fs";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function copyCarWars() {
return {
name: "copy-car-wars",
writeBundle: async () => {
const src = path.join(__dirname, "public/car-wars");
const dest = path.join(__dirname, "dist/car-wars");
try {
await fs.cp(src, dest, { recursive: true });
console.log("Copied public/car-wars to dist/car-wars");
} catch (e) {
console.warn("Could not copy public/car-wars to dist/car-wars:", e);
}
},
};
}
function copyIndexTo404() {
return {
name: "copy-index-to-404",
writeBundle: async () => {
const src = path.join(__dirname, "dist/index.html");
const dest = path.join(__dirname, "dist/404.html");
try {
await fs.copyFile(src, dest);
console.log("Copied dist/index.html to dist/404.html");
} catch (e) {
console.warn("Could not copy index.html to 404.html:", e);
}
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: "::",
port: 8080,
hmr: {
overlay: false,
},
},
plugins: [
tailwindcss(),
react(),
copyIndexTo404(),
copyCarWars(),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});