sure/vite.config.ts

80 lines
2.1 KiB
TypeScript

import { defineConfig } from "vite";
import { version } from "./package.json";
import { VitePWA } from "vite-plugin-pwa";
const isProduction = process.env.NODE_ENV === "production";
const API_BASE_URL = new URL(
process.env.VITE_API_BASE_URL || "http://localhost:3000"
);
const API_BASE_URL_SECURE = API_BASE_URL.protocol === "https:";
const BASE_URL = new URL(process.env.VITE_BASE_URL || "http://localhost:5137");
const BASE_URL_SECURE = BASE_URL.protocol === "https:";
export default defineConfig({
server: {
proxy: {
"/ws": {
target: API_BASE_URL_SECURE
? `wss://${API_BASE_URL.hostname}`
: `ws://${API_BASE_URL.hostname}`,
ws: true,
changeOrigin: true,
secure: isProduction,
},
"/api": {
target: BASE_URL_SECURE
? `https://${BASE_URL.hostname}`
: `http://${BASE_URL.hostname}`,
changeOrigin: true,
secure: isProduction,
},
},
},
define: {
"process.env.PACKAGE_VERSION": JSON.stringify(version),
"process.env.BUILD_TIME": JSON.stringify(new Date().toISOString()),
},
publicDir: "public",
plugins: [
VitePWA({
srcDir: "src",
filename: "sw.js",
registerType: "prompt",
includeAssets: [
"**/*.png",
"**/*.jpg",
"**/*.jpeg",
"**/*.svg",
"**/*.gif",
],
strategies: "injectManifest",
workbox: {
globPatterns: ["**/*"],
globDirectory: "dist",
},
manifest: {
name: "SURE",
short_name: "SURE",
theme_color: "#44a616",
background_color: "#3d006e",
display: "minimal-ui",
scope: "/",
start_url: "/",
icons: [
{
src: "/android-chrome-192x192.png",
sizes: "192x192",
type: "image/png",
},
{
src: "/android-chrome-512x512.png",
sizes: "512x512",
type: "image/png",
},
],
},
}),
],
});