update config

This commit is contained in:
SrGooglo 2024-10-29 21:11:21 +00:00
parent 3930d96e4c
commit a3ae6574e3

View File

@ -1,12 +1,16 @@
import path from "path" import path from "node:path"
import fs from "node:fs"
import aliases from "./aliases" import aliases from "./aliases"
import { defineConfig } from "vite" import { defineConfig } from "vite"
import react from "@vitejs/plugin-react" import react from "@vitejs/plugin-react"
const backendUri = "https://0.0.0.0:9000"
const oneYearInSeconds = 60 * 60 * 24 * 365 const oneYearInSeconds = 60 * 60 * 24 * 365
const sslDirPath = path.join(__dirname, ".ssl")
export default defineConfig({ const config = {
plugins: [ plugins: [
react(), react(),
], ],
@ -19,21 +23,17 @@ export default defineConfig({
fs: { fs: {
allow: ["..", "../../"], allow: ["..", "../../"],
}, },
https: {
key: path.join(__dirname, ".ssl", "privkey.pem"),
cert: path.join(__dirname, ".ssl", "cert.pem"),
},
headers: { headers: {
"Strict-Transport-Security": `max-age=${oneYearInSeconds}` "Strict-Transport-Security": `max-age=${oneYearInSeconds}`
}, },
proxy: { proxy: {
"/api": { "/api": {
target: "https://0.0.0.0:9000", target: backendUri,
rewrite: (path) => path.replace(/^\/api/, ""), rewrite: (path) => path.replace(/^\/api/, ""),
hostRewrite: true, hostRewrite: true,
changeOrigin: true, changeOrigin: true,
xfwd: true, xfwd: true,
//ws: true, ws: true,
toProxy: true, toProxy: true,
secure: false, secure: false,
} }
@ -56,8 +56,8 @@ export default defineConfig({
rollupOptions: { rollupOptions: {
output: { output: {
manualChunks(id) { manualChunks(id) {
if (id.includes('node_modules')) { if (id.includes("node_modules")) {
return id.toString().split('node_modules/')[1].split('/')[0].toString(); return id.toString().split("node_modules/")[1].split("/")[0].toString()
} }
} }
} }
@ -65,7 +65,16 @@ export default defineConfig({
}, },
esbuild: { esbuild: {
supported: { supported: {
"top-level-await": true //browsers can handle top-level-await features "top-level-await": true
}, },
} }
}) }
if (fs.existsSync(sslDirPath)) {
config.server.https = {
key: path.join(__dirname, ".ssl", "privkey.pem"),
cert: path.join(__dirname, ".ssl", "cert.pem"),
}
}
export default defineConfig(config)