|
1 | | -import { defineConfig } from "vite"; |
| 1 | +import { defineConfig, loadEnv } from "vite"; |
2 | 2 |
|
3 | 3 | // https://vitejs.dev/config/ |
4 | | -export default defineConfig({ |
5 | | - server: { |
6 | | - port: 3003, |
7 | | - open: false, // open the browser where app is started |
8 | | - proxy: { |
9 | | - // Proxy PostHog requests to avoid CORS issues |
10 | | - '/posthog': { |
11 | | - target: 'https://eu.i.posthog.com', |
12 | | - changeOrigin: true, |
13 | | - rewrite: (path) => path.replace(/^\/posthog/, ''), |
| 4 | +export default defineConfig(({ mode }) => { |
| 5 | + // Load env file based on `mode` in the current working directory. |
| 6 | + // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. |
| 7 | + const env = loadEnv(mode, process.cwd(), ''); |
| 8 | + |
| 9 | + return { |
| 10 | + server: { |
| 11 | + port: 3003, |
| 12 | + open: false, // open the browser where app is started |
| 13 | + proxy: { |
| 14 | + // Proxy PostHog requests to avoid CORS issues |
| 15 | + '/posthog': { |
| 16 | + target: 'https://eu.i.posthog.com', |
| 17 | + changeOrigin: true, |
| 18 | + rewrite: (path) => path.replace(/^\/posthog/, ''), |
| 19 | + }, |
14 | 20 | }, |
15 | 21 | }, |
16 | | - }, |
17 | | - publicDir: "public", |
18 | | - optimizeDeps: { |
19 | | - esbuildOptions: { |
20 | | - // Bumping to 2022 due to "Arbitrary module namespace identifier names" not being |
21 | | - // supported in Vite's default browser target https://github.com/vitejs/vite/issues/13556 |
22 | | - target: "es2022", |
23 | | - treeShaking: true, |
| 22 | + define: { |
| 23 | + // Make non-prefixed CODER_URL available to import.meta.env |
| 24 | + 'import.meta.env.CODER_URL': JSON.stringify(env.CODER_URL), |
24 | 25 | }, |
25 | | - }, |
| 26 | + publicDir: "public", |
| 27 | + optimizeDeps: { |
| 28 | + esbuildOptions: { |
| 29 | + // Bumping to 2022 due to "Arbitrary module namespace identifier names" not being |
| 30 | + // supported in Vite's default browser target https://github.com/vitejs/vite/issues/13556 |
| 31 | + target: "es2022", |
| 32 | + treeShaking: true, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }; |
26 | 36 | }); |
0 commit comments