Files
pasd_pc/vite.config.js
2025-07-28 14:59:31 +08:00

70 lines
2.0 KiB
JavaScript

import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import createVitePlugins from './vite/plugins'
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd())
const { VITE_APP_ENV } = env
return {
// 部署生产环境和开发环境下的URL.
base: VITE_APP_ENV === 'production' ? '/' : '/',
plugins: createVitePlugins(env, command === 'build'),
resolve: {
// https://cn.vitejs.dev/config/#resolve-alias
alias: {
'~': path.resolve(__dirname, './'),
'@': path.resolve(__dirname, './src')
},
// https://cn.vitejs.dev/config/#resolve-extensions
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
},
server: {
host: true,
open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'/dev-api': {
target: 'http://localhost:8080', // 测试
// target: 'http://172.16.129.101:8080', // 正式环境
changeOrigin: true,
rewrite: (p) => p.replace(/^\/dev-api/, '')
},
// 添加对第三方 API 的代理配置
'/api/v1/jssdk/upload': {
target: 'https://px.effirst.com',
changeOrigin: true,
rewrite: (p) => p.replace(/^\/api\/v1\/jssdk\/upload/, '/api/v1/jssdk/upload')
}
}
},
// fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
css: {
postcss: {
plugins: [
{
postcssPlugin: 'internal:charset-removal',
AtRule: {
charset: (atRule) => {
if (atRule.name === 'charset') {
atRule.remove();
}
}
}
}
]
}
},
build: {
target: 'es2015', // 指定编译目标
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
}
}
}
}
})