vite.config.ts 1.31 KB
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
const { resolve } = require('path')

// https://vitejs.dev/config/
export default ({command, mode}) => {
  const envConfig = loadEnv(mode, './');
  return defineConfig({
    plugins: [
      vue(),
      legacy({
        targets: ['> 1%, last 2 version, ie >= 11, chrome >= 69'],
        additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
        polyfills: false
      })
    ],
    resolve: {
      alias: {
        '@': resolve('./src')
      }
    },
    define: {
      'process.env': {}
    },
    server: {
      base: envConfig.VITE_BASE_URL,
    },
    css: {
      postcss: {
        plugins: [
          // 关打包@charset must be the first rule in the file警告
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset: (atRule) => {
                if (atRule.name === 'charset') {
                  atRule.remove();
                }
              }
            }
          }
        ]
      },
      preprocessorOptions: {
        scss: {
          // 关打包@charset must be the first rule in the file警告
          charset: false
        }
      }
    },
    build: {
      target: 'es2015',
      outDir: 'dist' 
    },
  })
}