forked from gradio-app/gradio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasevite.config.ts
93 lines (88 loc) · 2.11 KB
/
basevite.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
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import sveltePreprocess from "svelte-preprocess";
// @ts-ignore
import custom_media from "postcss-custom-media";
import global_data from "@csstools/postcss-global-data";
// @ts-ignore
import prefixer from "postcss-prefix-selector";
import { readFileSync } from "fs";
import { join } from "path";
import { fileURLToPath } from "url";
const __dirname = fileURLToPath(new URL(".", import.meta.url));
const version_path = join(__dirname, "..", "gradio", "package.json");
const theme_token_path = join(
__dirname,
"..",
"js",
"theme",
"src",
"tokens.css"
);
const version = JSON.parse(readFileSync(version_path, { encoding: "utf-8" }))
.version.trim()
.replace(/\./g, "-");
//@ts-ignore
export default defineConfig(({ mode }) => {
const production = mode === "production";
return {
server: {
port: 9876
},
build: {
sourcemap: false,
target: "esnext",
minify: production,
rollupOptions: {
external: ["virtual:component-loader"]
}
},
define: {
BUILD_MODE: production ? JSON.stringify("prod") : JSON.stringify("dev"),
BACKEND_URL: production
? JSON.stringify("")
: JSON.stringify("http://localhost:7860/"),
GRADIO_VERSION: JSON.stringify(version)
},
css: {
postcss: {
plugins: [
prefixer({
prefix: `.gradio-container-${version}`,
// @ts-ignore
transform(prefix, selector, prefixedSelector, fileName) {
if (selector.indexOf("gradio-container") > -1) {
return prefix;
} else if (
selector.indexOf(":root") > -1 ||
selector.indexOf("dark") > -1 ||
fileName.indexOf(".svelte") > -1
) {
return selector;
}
return prefixedSelector;
}
}),
custom_media()
]
}
},
plugins: [
svelte({
inspector: false,
compilerOptions: {
dev: !production
},
hot: !process.env.VITEST && !production,
preprocess: sveltePreprocess({
postcss: {
plugins: [
global_data({ files: [theme_token_path] }),
custom_media()
]
}
})
})
]
};
});