-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
97 lines (78 loc) · 2.54 KB
/
vite.config.ts
File metadata and controls
97 lines (78 loc) · 2.54 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
/*
* Copyright (c) 2025 Axel "Foley" Karlsson and contributors.
*
* Use of this source code is governed by the MIT License, which you may
* view in its entirety in the LICENSE file, found in the project's root directory.
*/
import { dirname, resolve } from "node:path"
import { fileURLToPath } from "node:url"
import fs from "node:fs"
import { defineConfig, loadEnv } from "vite"
import react from "@vitejs/plugin-react"
const __dirname = dirname(fileURLToPath(import.meta.url))
function writeSassConstants(constants: Record<string, string>): void {
let content =
"/*!\n" +
" * Copyright (c) 2025 Axel \"Foley\" Karlsson and contributors.\n" +
" *\n" +
" * Use of this source code is governed by the MIT License, which you may\n" +
" * view in its entirety in the LICENSE file, found in the project's root directory.\n" +
" */\n" +
"\n" +
"// --- DO NOT EDIT THIS FILE; IT IS AUTOMATICALLY GENERATED ---\n"
for (const [key, value] of Object.entries(constants)) {
content += `$${key}: "${value}"\n`
}
fs.writeFileSync(resolve(__dirname, "src/sass/_dynamic_constants.sass"), content)
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "")
if (!env.VITE_COMPONENT_PREFIX) {
throw Error("VITE_COMPONENT_PREFIX is undefined.")
}
writeSassConstants({
prefix: env.VITE_COMPONENT_PREFIX
})
return {
plugins: [
react()
],
build: {
// We do not want vite to clear the generated d.ts files.
emptyOutDir: false,
lib: {
entry: resolve(__dirname, "./src/index.ts"),
name: "SolidWeather-Components",
cssFileName: "index"
},
rolldownOptions: {
external: [ "react", "react-dom" ],
output: {
globals: {
"react": "React"
}
}
},
license: true
},
css: {
preprocessorOptions: {
sass: {
loadPaths: ["src/sass"]
}
}
},
server: {
// Required for the dev server to be accessible outside the Docker container.
host: "0.0.0.0",
watch: {
usePolling: true
}
},
resolve: {
alias: {
"@": resolve(__dirname, "./src")
}
}
}
})