import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
  plugins: [vue(), command === 'build' && legacy()].filter(Boolean),
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src'),
      '@img': path.join(__dirname, 'src/assets'),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData:
          '@import "@/style/_variables.scss", "@/style/_mixins.scss";',
      },
    },
  },
  base: '/ptc/',
  server: {
    proxy: {
      '/api': {
        target: 'http://t.ptcrepair.com.au/care',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, ''),
      },
      '/v2': {
        target: 'http://t.ptcrepair.com.au',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/v2/, ''),
      },
    },
  },
}))