on-site-robots-screen/vite.config.js

82 lines
2.6 KiB
JavaScript
Raw Normal View History

2025-06-17 16:01:11 +08:00
/**
* https://vitejs.dev/config/
* https://cn.vitejs.dev/config/#server-proxy
*/
2025-06-25 18:22:07 +08:00
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginAliOss from 'vite-plugin-ali-oss'
import ossOptionConfig from './oss.config'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
2025-06-17 16:01:11 +08:00
const pathResolve = (dir) => {
2025-06-25 18:22:07 +08:00
return resolve(__dirname, '.', dir)
}
2025-06-17 16:01:11 +08:00
const ossOptions = {
region: ossOptionConfig.region,
accessKeyId: ossOptionConfig.accessKeyId,
accessKeySecret: ossOptionConfig.accessKeySecret,
bucket: ossOptionConfig.bucket,
overwrite: true,
2025-06-25 18:22:07 +08:00
}
2025-06-17 16:01:11 +08:00
export default defineConfig(({ mode }) => {
2025-06-25 18:22:07 +08:00
const isProd = mode !== 'development'
const env = loadEnv(mode, process.cwd(), '') // 自定义的环境变量
let base = env.VITE_APP_biuldBase // 打包的静态资源的burl base
let outDir = 'dist'
2025-06-17 16:01:11 +08:00
let plugins = [
vue(),
AutoImport({
imports: [
'vue',
{
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar'],
},
],
}),
Components({
resolvers: [NaiveUiResolver()],
}),
2025-06-25 18:22:07 +08:00
]
2025-06-17 16:01:11 +08:00
/** 如果使用了alioss来储存文件 */
if (!!ossOptionConfig.url) {
2025-06-25 18:22:07 +08:00
base = ossOptionConfig.url + base
plugins.push(vitePluginAliOss(ossOptions))
2025-06-17 16:01:11 +08:00
}
return {
base: base, // must be URL when build
plugins: plugins,
build: {
/** 指定输出路径 */
outDir: outDir,
reportCompressedSize: false,
sourcemap: isProd ? false : true, // 这个生产环境一定要关闭,不然打包的产物会很大
},
resolve: {
alias: {
'@': pathResolve('./src'),
},
},
server: {
port: 8087,
host: true,
open: true,
proxy: {
'/api': {
2025-06-25 18:22:07 +08:00
target: 'http://192.168.0.38:58080', // 郝志权测试环境
changeOrigin: true,
rewrite: (p) => p.replace(/^\/api/, ''),
},
'/third-party': {
2025-06-17 16:01:11 +08:00
// target: 'http://127.0.0.1:8089',
2025-06-25 18:22:07 +08:00
target: 'https://cs.fydl.cloud:39979/icvs2/',
2025-06-17 16:01:11 +08:00
changeOrigin: true,
2025-06-25 18:22:07 +08:00
rewrite: (p) => p.replace(/^\/third-party/, ''),
2025-06-17 16:01:11 +08:00
},
},
},
2025-06-25 18:22:07 +08:00
}
})