-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
103 lines (93 loc) · 2.66 KB
/
vite.config.js
File metadata and controls
103 lines (93 loc) · 2.66 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
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig, loadEnv } from "vite";
import fs from "fs";
import path from "path";
const env = loadEnv("", process.cwd());
function copyLangFolderPlugin() {
let outDir = "";
return {
name: "copy-lang-folder",
apply: "build", // Run only during build
configResolved(config) {
// Get the output directory from Vite config
outDir = "build/";
},
async closeBundle() {
const srcDir = path.resolve(process.cwd(), "lang");
const destDir = path.resolve(process.cwd(), outDir, "lang");
if (!fs.existsSync(srcDir)) {
console.warn(`Source folder "lang" not found at: ${srcDir}`);
return;
}
try {
// Copy the "lang" folder recursively to the destination
await fs.promises.cp(srcDir, destDir, { recursive: true });
console.log(`Copied "lang" folder from ${srcDir} to ${destDir}`);
} catch (error) {
console.error("Error copying \"lang\" folder:", error);
}
}
};
}
function copyManifestPlugin(filename = "manifest.json") {
let outDir = "";
return {
name: "copy-manifest-json",
apply: "build",
configResolved(config) {
outDir = "build/";
},
async closeBundle() {
const srcPath = path.resolve(process.cwd(), filename);
const destPath = path.resolve(process.cwd(), outDir, filename);
if (!fs.existsSync(srcPath)) {
console.warn(`Manifest file not found at: ${srcPath}`);
return;
}
try {
await fs.promises.copyFile(srcPath, destPath);
console.log(`Copied manifest from ${srcPath} to ${destPath}`);
} catch (err) {
console.error("Failed to copy manifest.json:", err);
}
}
};
}
export default defineConfig(({ command }) => {
return {
clearScreen: false,
plugins: [sveltekit(), copyLangFolderPlugin(), copyManifestPlugin()],
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
loadPaths: [process.cwd(), path.resolve(process.cwd(), 'node_modules')],
quietDeps: true,
silenceDeprecations: [
"mixed-decls",
"color-functions",
"global-builtin",
"import",
],
},
},
},
server: {
proxy: {
"/api": env.VITE_API_URL.replace("/api", ""),
},
allowedHosts: true,
hmr: {
path: "/",
},
},
resolve: {
alias: {
"@theme-style":
command === "serve"
? path.resolve(process.cwd(), "src/styles/_empty.scss")
: path.resolve(process.cwd(), "src/styles/style.scss"),
},
},
};
});