import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2'
import importerPlugin from 'vite-plugin-importer'

import path from 'path'

export default defineConfig({
  base: '',

  plugins: [
    createVuePlugin({
      jsx: true,
      compilerOptions: {
        whitespace: 'condense'
      },
      jsxOptions: {
        compositionAPI: true
      }
    }),
    importerPlugin({
      libraryName: 'element-ui'
    })
  ],

  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/styles/variables.scss";',
        javascriptEnabled: true
      }
    }
  },

  resolve: {
    alias: {
      '@': path.join(__dirname, 'src'),
      '~': path.join(__dirname)
    },
    extensions: ['.js', '.vue']
  },

  server: {
    host: '0.0.0.0',
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    proxy: {
      '/api': {
        target: 'http://0.0.0.0:3000',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  }
})
