You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2KB

  1. import { defineConfig, loadEnv } from 'vite'
  2. import { resolve } from 'path'
  3. import { wrapperEnv } from './build/utils'
  4. import { createVitePlugins } from './build/vite/plugin'
  5. import { createProxy } from './build/vite/proxy'
  6. import { OUTPUT_DIR } from './build/constant'
  7. function pathResolve(dir) {
  8. return resolve(__dirname, '.', dir)
  9. }
  10. export default defineConfig(({ command, mode }) => {
  11. const root = process.cwd()
  12. const isBuild = command === 'build'
  13. const env = loadEnv(mode, process.cwd())
  14. const viteEnv = wrapperEnv(env)
  15. const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv
  16. return {
  17. root,
  18. base: VITE_PUBLIC_PATH || '/',
  19. plugins: createVitePlugins(viteEnv, isBuild),
  20. lintOnSave: false,
  21. resolve: {
  22. alias: {
  23. '@': pathResolve('src')
  24. }
  25. },
  26. css: {
  27. preprocessorOptions: {
  28. scss: {
  29. additionalData: `@import '@/styles/variables.scss';`
  30. }
  31. }
  32. },
  33. server: {
  34. host: '0.0.0.0',
  35. port: VITE_PORT,
  36. proxy: createProxy(VITE_PROXY)
  37. },
  38. build: {
  39. target: 'es2015',
  40. outDir: OUTPUT_DIR,
  41. brotliSize: false,
  42. chunkSizeWarningLimit: 2000
  43. }
  44. }
  45. })