| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { defineConfig, loadEnv } from 'vite'
- import uni from '@dcloudio/vite-plugin-uni'
- // import { resolve } from 'path'
- export default defineConfig(({ command, mode }) => {
- // 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
- const env = loadEnv(mode, process.cwd(), '')
- if (mode === 'development' || mode === 'sandbox') {
- // 测试环境配置
- return {
- base: '/',
- plugins: [uni()],
- // envDir: resolve(__dirname, 'env'),
- define: {
- __VITE_BASE_URL__: JSON.stringify(env.VITE_BASE_URL)
- },
- server: {
- port: 5174
- }
- }
- } else if (mode === 'production') {
- // 生产环境配置
- return {
- plugins: [uni()],
- // envDir: resolve(__dirname, 'env'),
- define: {
- __VITE_BASE_URL__: JSON.stringify(env.VITE_BASE_URL)
- },
- // 删除console
- build: {
- minify: 'terser',
- terserOptions: {
- compress: {
- drop_console: true
- }
- }
- }
- }
- } else {
- // 本地开发环境配置
- return {
- plugins: [uni()],
- // envDir: resolve(__dirname, 'env'),
- define: {
- __VITE_BASE_URL__: JSON.stringify(env.VITE_BASE_URL)
- },
- server: {
- port: 5174
- }
- }
- }
- })
|