|
|
import { defineConfig, loadEnv } from 'vite' |
|
|
import vue from '@vitejs/plugin-vue' |
|
|
import checker from 'vite-plugin-checker' |
|
|
import AutoImport from 'unplugin-auto-import/vite' |
|
|
import Components from 'unplugin-vue-components/vite' |
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' |
|
|
import { fileURLToPath, URL } from 'node:url' |
|
|
|
|
|
export default defineConfig(({ mode }) => { |
|
|
|
|
|
const env = loadEnv(mode, process.cwd(), '') |
|
|
const apiTarget = env.VITE_API_TARGET || 'http://localhost:3000' |
|
|
const httpProxy = env.VITE_HTTP_PROXY || env.HTTP_PROXY || env.http_proxy |
|
|
|
|
|
const basePath = env.VITE_APP_BASE_URL || (mode === 'development' ? '/admin/' : '/admin-next/') |
|
|
|
|
|
|
|
|
const proxyConfig = { |
|
|
target: apiTarget, |
|
|
changeOrigin: true, |
|
|
secure: false |
|
|
} |
|
|
|
|
|
|
|
|
if (httpProxy && mode === 'development') { |
|
|
console.log(`Using HTTP proxy: ${httpProxy}`) |
|
|
|
|
|
|
|
|
process.env.HTTP_PROXY = httpProxy |
|
|
process.env.HTTPS_PROXY = httpProxy |
|
|
} |
|
|
|
|
|
console.log( |
|
|
`${mode === 'development' ? 'Starting dev server' : 'Building'} with base path: ${basePath}` |
|
|
) |
|
|
|
|
|
return { |
|
|
base: basePath, |
|
|
plugins: [ |
|
|
vue(), |
|
|
checker({ |
|
|
eslint: { |
|
|
lintCommand: 'eslint "./src/**/*.{js,vue}" --cache=false', |
|
|
dev: { |
|
|
logLevel: ['error', 'warning'] |
|
|
} |
|
|
} |
|
|
}), |
|
|
AutoImport({ |
|
|
resolvers: [ElementPlusResolver()], |
|
|
imports: ['vue', 'vue-router', 'pinia'] |
|
|
}), |
|
|
Components({ |
|
|
resolvers: [ElementPlusResolver()] |
|
|
}) |
|
|
], |
|
|
resolve: { |
|
|
alias: { |
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)) |
|
|
} |
|
|
}, |
|
|
server: { |
|
|
port: 3001, |
|
|
host: true, |
|
|
open: true, |
|
|
proxy: { |
|
|
|
|
|
'/webapi': { |
|
|
...proxyConfig, |
|
|
rewrite: (path) => path.replace(/^\/webapi/, ''), |
|
|
configure: (proxy, options) => { |
|
|
proxy.on('proxyReq', (proxyReq, req) => { |
|
|
console.log( |
|
|
'Proxying:', |
|
|
req.method, |
|
|
req.url, |
|
|
'->', |
|
|
options.target + req.url.replace(/^\/webapi/, '') |
|
|
) |
|
|
}) |
|
|
proxy.on('error', (err) => { |
|
|
console.log('Proxy error:', err) |
|
|
}) |
|
|
} |
|
|
}, |
|
|
|
|
|
'/apiStats': { |
|
|
...proxyConfig, |
|
|
configure: (proxy, options) => { |
|
|
proxy.on('proxyReq', (proxyReq, req) => { |
|
|
console.log( |
|
|
'API Stats Proxying:', |
|
|
req.method, |
|
|
req.url, |
|
|
'->', |
|
|
options.target + req.url |
|
|
) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
build: { |
|
|
outDir: 'dist', |
|
|
assetsDir: 'assets', |
|
|
rollupOptions: { |
|
|
output: { |
|
|
manualChunks(id) { |
|
|
|
|
|
if (id.includes('node_modules')) { |
|
|
if (id.includes('element-plus')) { |
|
|
return 'element-plus' |
|
|
} |
|
|
if (id.includes('chart.js')) { |
|
|
return 'chart' |
|
|
} |
|
|
if (id.includes('vue') || id.includes('pinia') || id.includes('vue-router')) { |
|
|
return 'vue-vendor' |
|
|
} |
|
|
return 'vendor' |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
|