| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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: '/h5/',
- plugins: [uni()],
- // envDir: resolve(__dirname, 'env'),
- define: {
- __VITE_BASE_URL__: JSON.stringify(env.VITE_BASE_URL)
- },
- server: {
- port: 5174
- }
- }
- } else if (mode === 'production') {
- // 生产环境配置
- return {
- base: '/h5/',
- 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
- }
- }
- }
- })
|