vite.config.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { defineConfig, loadEnv } from 'vite';
  2. import createPlugins from './vite/plugins';
  3. import autoprefixer from 'autoprefixer'; // css自动添加兼容性前缀
  4. import path from 'path';
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd());
  7. return {
  8. // 部署生产环境和开发环境下的URL。
  9. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  10. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  11. base: env.VITE_APP_CONTEXT_PATH,
  12. resolve: {
  13. alias: {
  14. '@': path.resolve(__dirname, './src')
  15. },
  16. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  17. },
  18. // https://cn.vitejs.dev/config/#resolve-extensions
  19. plugins: createPlugins(env, command === 'build'),
  20. server: {
  21. host: '0.0.0.0',
  22. allowedHosts: [
  23. 'index.xiaoluwebsite.xyz',
  24. 'b.xiaoluwebsite.xyz',
  25. 'mro.xiaoluwebsite.xyz',
  26. 'fuli.xiaoluwebsite.xyz',
  27. 'reg.xiaoluwebsite.xyz',
  28. 'breg.xiaoluwebsite.xyz',
  29. 'greg.xiaoluwebsite.xyz',
  30. 'pass.xiaoluwebsite.xyz',
  31. 'search.xiaoluwebsite.xyz',
  32. 'item.xiaoluwebsite.xyz',
  33. 'cart.xiaoluwebsite.xyz',
  34. 'trad.xiaoluwebsite.xyz',
  35. 'payc.xiaoluwebsite.xyz',
  36. 'order.xiaoluwebsite.xyz',
  37. 'plan.xiaoluwebsite.xyz',
  38. 'planinfo.xiaoluwebsite.xyz',
  39. 'i.xiaoluwebsite.xyz',
  40. 'easybuv.xiaoluwebsite.xyz'
  41. ],
  42. port: Number(env.VITE_APP_PORT),
  43. // port: Number(env.VITE_APP_PORT),
  44. open: true,
  45. proxy: {
  46. [env.VITE_APP_BASE_API]: {
  47. // target: 'http://localhost:8080',
  48. // target: 'http://yp1.yingpaipay.com:9026',
  49. target: 'https://jingyang.xiaoluwebsite.xyz',
  50. // target: 'https://one.yoe365.com',
  51. // target: 'http://192.168.1.52:8080',
  52. // target: 'https://apiyouyida.xiaoluwebsite.xyz',//线上
  53. changeOrigin: true,
  54. ws: true,
  55. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  56. }
  57. }
  58. },
  59. css: {
  60. preprocessorOptions: {
  61. scss: {
  62. // additionalData: '@use "@/assets/styles/variables.module.scss as *";'
  63. // javascriptEnabled: true
  64. api: 'modern-compiler'
  65. }
  66. },
  67. postcss: {
  68. plugins: [
  69. // 浏览器兼容性
  70. autoprefixer(),
  71. {
  72. postcssPlugin: 'internal:charset-removal',
  73. AtRule: {
  74. charset: (atRule) => {
  75. atRule.remove();
  76. }
  77. }
  78. }
  79. ]
  80. }
  81. },
  82. // 预编译
  83. optimizeDeps: {
  84. include: [
  85. 'vue',
  86. 'vue-router',
  87. 'pinia',
  88. 'axios',
  89. '@vueuse/core',
  90. 'echarts',
  91. 'vue-i18n',
  92. '@vueup/vue-quill',
  93. 'image-conversion',
  94. 'element-plus/es/components/**/css'
  95. ]
  96. }
  97. };
  98. });