2022-02-02 02:25:20 +08:00
|
|
|
import { defineConfig } from "vite";
|
|
|
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
|
|
import sveltePreprocess from "svelte-preprocess";
|
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
|
|
|
|
|
|
|
// this is dupe config, gonna try fix this
|
|
|
|
import tailwind from "tailwindcss";
|
2022-07-22 02:12:46 +08:00
|
|
|
// @ts-ignore
|
2022-03-23 23:19:12 +08:00
|
|
|
import nested from "tailwindcss/nesting/index.js";
|
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
|
|
|
|
2022-02-03 18:35:14 +08:00
|
|
|
build: {
|
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("")
|
|
|
|
: JSON.stringify("http://localhost:7860/")
|
2022-02-02 02:25:20 +08:00
|
|
|
},
|
2022-02-18 05:21:18 +08:00
|
|
|
css: {
|
|
|
|
postcss: {
|
|
|
|
plugins: [nested, tailwind]
|
|
|
|
}
|
|
|
|
},
|
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({
|
2022-03-12 00:00:48 +08:00
|
|
|
postcss: { plugins: [tailwind, nested] }
|
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
|
|
|
};
|
|
|
|
});
|