| 1 | import fs from "node:fs" |
| 2 | import process from "node:process" |
| 3 | import { fileURLToPath, URL } from "node:url" |
| 4 | import tailwindcss from "@tailwindcss/vite" |
| 5 | import vue from "@vitejs/plugin-vue" |
| 6 | import vueJsx from "@vitejs/plugin-vue-jsx" |
| 7 | import { defineConfig, loadEnv } from "vite" |
| 8 | import VueDevTools from "vite-plugin-vue-devtools" |
| 9 | import svgLoader from "vite-svg-loader" |
| 10 | // import { analyzer } from "vite-bundle-analyzer" |
| 11 | |
| 12 | // https://vitejs.dev/config/ |
| 13 | export default defineConfig(({ mode }) => { |
| 14 | // Load env file based on `mode` in the current working directory. |
| 15 | // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. |
| 16 | process.env = { ...process.env, ...loadEnv(mode, process.cwd(), "") } |
| 17 | |
| 18 | return { |
| 19 | plugins: [ |
| 20 | tailwindcss(), |
| 21 | vue({ |
| 22 | script: { |
| 23 | defineModel: true |
| 24 | } |
| 25 | }), |
| 26 | vueJsx(), |
| 27 | VueDevTools({ |
| 28 | launchEditor: "cursor" |
| 29 | }), |
| 30 | svgLoader() |
| 31 | // uncomment to enable analyzer after build |
| 32 | // analyzer() |
| 33 | ], |
| 34 | resolve: { |
| 35 | alias: { |
| 36 | "@": fileURLToPath(new URL("./src", import.meta.url)) |
| 37 | } |
| 38 | }, |
| 39 | optimizeDeps: { |
| 40 | include: ["fast-deep-equal"] |
| 41 | }, |
| 42 | server: { |
| 43 | port: 3001, |
| 44 | https: |
| 45 | fs.existsSync("/certs/key.pem") && fs.existsSync("/certs/cert.pem") |
| 46 | ? { key: fs.readFileSync("/certs/key.pem"), cert: fs.readFileSync("/certs/cert.pem") } |
| 47 | : undefined, |
| 48 | proxy: Object.fromEntries( |
| 49 | ["/api", "/ws", "/celery", "/monitoring"].map(path => [ |
| 50 | path, |
| 51 | { |
| 52 | target: process.env.VITE_API_URL || "http://127.0.0.1:5000", |
| 53 | changeOrigin: true |
| 54 | } |
| 55 | ]) |
| 56 | ) |
| 57 | }, |
| 58 | define: { |
| 59 | __APP_ENV__: JSON.stringify(process.env.APP_ENV) |
| 60 | }, |
| 61 | css: { |
| 62 | preprocessorOptions: { |
| 63 | scss: { |
| 64 | silenceDeprecations: ["legacy-js-api", "import"], |
| 65 | api: "modern-compiler" |
| 66 | } |
| 67 | } |
| 68 | }, |
| 69 | build: { |
| 70 | rollupOptions: { |
| 71 | onwarn(warning, warn) { |
| 72 | if (warning.code === "PLUGIN_WARNING" && warning.message.includes('Module "node:process"')) { |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | warn(warning) |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | }) |