import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
  transpileDependencies: [
    /[/\\]node_modules[/\\](.+?)?@uni-ui(.*)[/\\]code-plugs/
  ],
  plugins: [
    uni(),
    AutoImport({
      imports: [
        'vue',
        'uni-app'
      ],
      dirs: [
        'src/utils/**',
        'src/wxs/**'
      ],
      dts: 'src/auto-import/imports.d.ts',
      eslintrc: {
        enabled: true
      }
    })
  ].concat(process.env.UNI_PLATFORM === 'h5' ? [
    legacy({
      // 兼容浏览器列表
      targets: ['Android >= 7', 'chrome >= 51', 'firefox >= 54', 'ios >= 10']
    })
  ] : []),
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  server: {
    host: true,
    port: 80,
    open: true
  },
  build: {
    minify: 'terser'
  }
})
