49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
import Vue from '@vitejs/plugin-vue'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
// 只在建置設定內讀取(不進 client bundle):後端目前沒有開放 CORS,
|
|
// 本機開發改用 dev server 轉發 /api,避開瀏覽器的跨網域限制。
|
|
// 在 .env.local 設定 API_PROXY_TARGET(例如內網後端位址)即可啟用;
|
|
// 未設定時維持原行為(前端走 VITE_USE_MOCK 的模擬資料)。
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
const apiProxyTarget = env.API_PROXY_TARGET
|
|
|
|
return {
|
|
plugins: [
|
|
Vue({
|
|
template: { transformAssetUrls },
|
|
}),
|
|
// https://github.com/vuetifyjs/vuetify-loader/tree/master/packages/vite-plugin#readme
|
|
Vuetify({
|
|
autoImport: true,
|
|
styles: {
|
|
configFile: 'src/styles/settings.scss',
|
|
},
|
|
}),
|
|
],
|
|
define: { 'process.env': {} },
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('src', import.meta.url)),
|
|
},
|
|
extensions: ['.js', '.json', '.jsx', '.mjs', '.ts', '.tsx', '.vue'],
|
|
},
|
|
server: {
|
|
port: 3678,
|
|
proxy: apiProxyTarget
|
|
? {
|
|
'/api': {
|
|
target: apiProxyTarget,
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(/^\/api/, ''),
|
|
},
|
|
}
|
|
: undefined,
|
|
},
|
|
}
|
|
})
|