| 1 | import type { RollupLog, RollupLogWithString } from "rolldown" |
| 2 | import fs from "node:fs" |
| 3 | import process from "node:process" |
| 4 | import { fileURLToPath, URL } from "node:url" |
| 5 | import tailwindcss from "@tailwindcss/vite" |
| 6 | import vue from "@vitejs/plugin-vue" |
| 7 | import vueJsx from "@vitejs/plugin-vue-jsx" |
| 8 | import { defineConfig, loadEnv } from "vite" |
| 9 | import VueDevTools from "vite-plugin-vue-devtools" |
| 10 | import svgLoader from "vite-svg-loader" |
| 11 | // import { analyzer } from "vite-bundle-analyzer" |
| 12 | |
| 13 | function suppressRolldownIifeNameWarning( |
| 14 | warning: RollupLog, |
| 15 | defaultHandler: (warning: RollupLogWithString | (() => RollupLogWithString)) => void |
| 16 | ) { |
| 17 | if (warning.code === "MISSING_NAME_OPTION_FOR_IIFE_EXPORT") { |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | defaultHandler(warning) |
| 22 | } |
| 23 | |
| 24 | // https://vitejs.dev/config/ |
| 25 | export default defineConfig(({ mode, command }) => { |
| 26 | // Load env file based on `mode` in the current working directory. |
| 27 | // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. |
| 28 | process.env = { ...process.env, ...loadEnv(mode, process.cwd(), "") } |
| 29 | |
| 30 | return { |
| 31 | plugins: [ |
| 32 | tailwindcss(), |
| 33 | vue({ |
| 34 | script: { |
| 35 | defineModel: true |
| 36 | }, |
| 37 | template: { |
| 38 | compilerOptions: { |
| 39 | isCustomElement: (tag: string) => tag === "app-search-bar" |
| 40 | } |
| 41 | } |
| 42 | }), |
| 43 | vueJsx(), |
| 44 | ...(command === "serve" |
| 45 | ? [ |
| 46 | VueDevTools({ |
| 47 | launchEditor: "cursor" |
| 48 | }) |
| 49 | ] |
| 50 | : []), |
| 51 | svgLoader() |
| 52 | // uncomment to enable analyzer after build |
| 53 | // analyzer() |
| 54 | ], |
| 55 | resolve: { |
| 56 | alias: { |
| 57 | "@": fileURLToPath(new URL("./src", import.meta.url)) |
| 58 | } |
| 59 | }, |
| 60 | optimizeDeps: { |
| 61 | exclude: ["xmllint-wasm"], |
| 62 | // include: ["fast-deep-equal"], |
| 63 | rolldownOptions: { |
| 64 | onwarn: suppressRolldownIifeNameWarning |
| 65 | } |
| 66 | }, |
| 67 | server: { |
| 68 | allowedHosts: true, |
| 69 | https: |
| 70 | fs.existsSync("/certs/key.pem") && fs.existsSync("/certs/cert.pem") |
| 71 | ? { key: fs.readFileSync("/certs/key.pem"), cert: fs.readFileSync("/certs/cert.pem") } |
| 72 | : undefined, |
| 73 | proxy: { |
| 74 | "/api": { |
| 75 | // target: "http://copilot-backend:5000", |
| 76 | target: process.env.VITE_API_URL, |
| 77 | changeOrigin: true |
| 78 | } |
| 79 | } |
| 80 | }, |
| 81 | define: { |
| 82 | __APP_ENV__: JSON.stringify(process.env.APP_ENV) |
| 83 | }, |
| 84 | css: { |
| 85 | preprocessorOptions: { |
| 86 | scss: { |
| 87 | silenceDeprecations: ["legacy-js-api", "import"], |
| 88 | api: "modern-compiler" |
| 89 | } |
| 90 | } |
| 91 | }, |
| 92 | build: { |
| 93 | rolldownOptions: { |
| 94 | onwarn: suppressRolldownIifeNameWarning |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | }) |