2022-02-02 02:25:20 +08:00
|
|
|
import { defineConfig } from "vite";
|
|
|
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
|
|
import sveltePreprocess from "svelte-preprocess";
|
2023-01-18 04:47:40 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import custom_media from "postcss-custom-media";
|
2023-01-28 17:47:14 +08:00
|
|
|
// @ts-ignore
|
|
|
|
import prefixer from "postcss-prefix-selector";
|
|
|
|
import { readFileSync } from "fs";
|
|
|
|
import { join } from "path";
|
|
|
|
|
|
|
|
const version_path = join(__dirname, "..", "..", "..", "gradio", "version.txt");
|
|
|
|
const version = readFileSync(version_path, { encoding: "utf-8" })
|
|
|
|
.trim()
|
|
|
|
.replace(/\./g, "-");
|
2022-05-17 01:22:09 +08:00
|
|
|
|
2022-05-27 09:17:13 +08:00
|
|
|
import {
|
|
|
|
inject_ejs,
|
|
|
|
patch_dynamic_import,
|
2022-06-08 02:11:44 +08:00
|
|
|
generate_cdn_entry,
|
|
|
|
handle_ce_css
|
2022-05-27 09:17:13 +08:00
|
|
|
} from "./build_plugins";
|
2022-02-02 02:25:20 +08:00
|
|
|
|
2022-06-08 02:11:44 +08:00
|
|
|
const GRADIO_VERSION = process.env.GRADIO_VERSION || "asd_stub_asd";
|
|
|
|
const TEST_CDN = !!process.env.TEST_CDN;
|
|
|
|
const CDN = TEST_CDN
|
|
|
|
? "http://localhost:4321/"
|
|
|
|
: `https://gradio.s3-us-west-2.amazonaws.com/${GRADIO_VERSION}/`;
|
2022-05-16 03:43:36 +08:00
|
|
|
|
2022-02-18 05:21:18 +08:00
|
|
|
//@ts-ignore
|
2022-02-02 02:25:20 +08:00
|
|
|
export default defineConfig(({ mode }) => {
|
2022-06-08 02:11:44 +08:00
|
|
|
const CDN_URL = mode === "production:cdn" ? CDN : "/";
|
2022-05-16 23:45:38 +08:00
|
|
|
const production =
|
|
|
|
mode === "production:cdn" ||
|
|
|
|
mode === "production:local" ||
|
|
|
|
mode === "production:website";
|
|
|
|
const is_cdn = mode === "production:cdn" || mode === "production:website";
|
2022-02-02 02:25:20 +08:00
|
|
|
|
|
|
|
return {
|
2022-05-16 03:43:36 +08:00
|
|
|
base: is_cdn ? CDN_URL : "./",
|
2022-05-17 01:22:09 +08:00
|
|
|
|
2023-01-18 04:47:40 +08:00
|
|
|
server: {
|
2023-01-27 22:39:36 +08:00
|
|
|
port: 9876
|
2023-01-18 04:47:40 +08:00
|
|
|
},
|
|
|
|
|
2022-02-03 18:35:14 +08:00
|
|
|
build: {
|
2022-10-26 07:57:13 +08:00
|
|
|
sourcemap: true,
|
2022-05-16 03:43:36 +08:00
|
|
|
target: "esnext",
|
2022-10-06 05:11:47 +08:00
|
|
|
minify: production,
|
2022-05-16 03:43:36 +08:00
|
|
|
outDir: `../../../gradio/templates/${is_cdn ? "cdn" : "frontend"}`
|
2022-02-03 18:35:14 +08:00
|
|
|
},
|
2022-02-02 02:25:20 +08:00
|
|
|
define: {
|
|
|
|
BUILD_MODE: production ? JSON.stringify("prod") : JSON.stringify("dev"),
|
2022-03-31 23:48:54 +08:00
|
|
|
BACKEND_URL: production
|
|
|
|
? JSON.stringify("")
|
2023-01-28 17:47:14 +08:00
|
|
|
: JSON.stringify("http://localhost:7860/"),
|
|
|
|
GRADIO_VERSION: JSON.stringify(version)
|
2022-02-02 02:25:20 +08:00
|
|
|
},
|
2022-02-18 05:21:18 +08:00
|
|
|
css: {
|
|
|
|
postcss: {
|
2023-01-18 04:47:40 +08:00
|
|
|
plugins: [
|
2023-01-28 17:47:14 +08:00
|
|
|
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;
|
|
|
|
} else {
|
|
|
|
return prefixedSelector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
2023-01-18 04:47:40 +08:00
|
|
|
custom_media({
|
|
|
|
importFrom: [
|
|
|
|
{
|
|
|
|
customMedia: {
|
|
|
|
"--screen-sm": "(min-width: 640px)",
|
|
|
|
"--screen-md": "(min-width: 768px)",
|
|
|
|
"--screen-lg": "(min-width: 1024px)",
|
|
|
|
"--screen-xl": "(min-width: 1280px)",
|
|
|
|
"--screen-xxl": "(min-width: 1536px)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
2022-02-18 05:21:18 +08:00
|
|
|
}
|
|
|
|
},
|
2022-02-02 02:25:20 +08:00
|
|
|
plugins: [
|
|
|
|
svelte({
|
2022-05-13 04:27:21 +08:00
|
|
|
experimental: {
|
|
|
|
inspector: true
|
|
|
|
},
|
2022-05-17 01:22:09 +08:00
|
|
|
compilerOptions: {
|
|
|
|
dev: !production
|
|
|
|
},
|
2022-06-08 02:11:44 +08:00
|
|
|
hot: !process.env.VITEST && !production,
|
2022-02-02 02:25:20 +08:00
|
|
|
preprocess: sveltePreprocess({
|
2023-01-28 17:47:14 +08:00
|
|
|
postcss: {
|
|
|
|
plugins: [custom_media()]
|
|
|
|
}
|
2022-02-02 02:25:20 +08:00
|
|
|
})
|
2022-05-04 05:44:17 +08:00
|
|
|
}),
|
2022-05-27 09:17:13 +08:00
|
|
|
inject_ejs(),
|
|
|
|
patch_dynamic_import({
|
|
|
|
mode: is_cdn ? "cdn" : "local",
|
|
|
|
gradio_version: GRADIO_VERSION,
|
|
|
|
cdn_url: CDN_URL
|
|
|
|
}),
|
2022-06-08 02:11:44 +08:00
|
|
|
generate_cdn_entry({ enable: is_cdn, cdn_url: CDN_URL }),
|
|
|
|
handle_ce_css()
|
2022-03-23 23:19:12 +08:00
|
|
|
],
|
|
|
|
test: {
|
|
|
|
environment: "happy-dom",
|
|
|
|
include: ["**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"]
|
|
|
|
}
|
2022-02-02 02:25:20 +08:00
|
|
|
};
|
|
|
|
});
|