vite.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd())
  7. const { VITE_APP_ENV } = env
  8. return {
  9. base: VITE_APP_ENV === 'production' ? '/' : '/',
  10. plugins: createVitePlugins(env, command === 'build'),
  11. resolve: {
  12. alias: {
  13. // 设置路径
  14. '~': path.resolve(__dirname, './'),
  15. // 设置别名
  16. '@': path.resolve(__dirname, './src')
  17. },
  18. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  19. },
  20. // vite 相关配置
  21. server: {
  22. port: 8080,
  23. host: true,
  24. open: true,
  25. proxy: {
  26. // https://cn.vitejs.dev/config/#server-proxy
  27. '/dev-api': {
  28. // target: 'http://192.168.11.46:8080',
  29. target: 'http://182.43.195.17:8010',
  30. changeOrigin: true,
  31. rewrite: (p) => p.replace(/^\/dev-api/, '')
  32. },
  33. '/APP': {
  34. target: 'http://182.43.247.65:8000',
  35. changeOrigin: true,
  36. rewrite: (path) => path.replace(/^\/APP/, '')
  37. }
  38. }
  39. },
  40. css: {
  41. postcss: {
  42. plugins: [
  43. {
  44. postcssPlugin: 'internal:charset-removal',
  45. AtRule: {
  46. charset: (atRule) => {
  47. if (atRule.name === 'charset') {
  48. atRule.remove();
  49. }
  50. }
  51. }
  52. }
  53. ]
  54. }
  55. }
  56. }
  57. })