1
import { defineConfig } from "vite";
2
import { svelte } from "@sveltejs/vite-plugin-svelte";
3
import sveltePreprocess from "svelte-preprocess";
5
import custom_media from "postcss-custom-media";
6
import global_data from "@csstools/postcss-global-data";
8
import prefixer from "postcss-prefix-selector";
9
import { readFileSync } from "fs";
10
import { join } from "path";
11
import { fileURLToPath } from "url";
13
const __dirname = fileURLToPath(new URL(".", import.meta.url));
14
const version_path = join(__dirname, "..", "gradio", "package.json");
15
const theme_token_path = join(
24
const version = JSON.parse(readFileSync(version_path, { encoding: "utf-8" }))
29
export default defineConfig(({ mode }) => {
30
const production = mode === "production";
43
BUILD_MODE: production ? JSON.stringify("prod") : JSON.stringify("dev"),
44
BACKEND_URL: production
46
: JSON.stringify("http://localhost:7860/"),
47
GRADIO_VERSION: JSON.stringify(version)
53
prefix: `.gradio-container-${version}`,
55
transform(prefix, selector, prefixedSelector, fileName) {
56
if (selector.indexOf("gradio-container") > -1) {
59
selector.indexOf(":root") > -1 ||
60
selector.indexOf("dark") > -1 ||
61
fileName.indexOf(".svelte") > -1
65
return prefixedSelector;
78
hot: !process.env.VITEST && !production,
79
preprocess: sveltePreprocess({
82
global_data({ files: [theme_token_path] }),