vite.config.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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:8081',
  35. target: 'http://192.168.0.196:8000',
  36. changeOrigin: true,
  37. rewrite: (path) => path.replace(/^\/APP/, '')
  38. }
  39. }
  40. },
  41. css: {
  42. postcss: {
  43. plugins: [
  44. {
  45. postcssPlugin: 'internal:charset-removal',
  46. AtRule: {
  47. charset: (atRule) => {
  48. if (atRule.name === 'charset') {
  49. atRule.remove();
  50. }
  51. }
  52. }
  53. }
  54. ]
  55. }
  56. }
  57. }
  58. })