vite.config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. port: Number(env.VITE_APP_PORT),
  23. open: true,
  24. proxy: {
  25. // 小程序后端代理(用于图片等静态资源)
  26. '/miniapp-api': {
  27. target: 'http://localhost:8081',
  28. changeOrigin: true,
  29. ws: true,
  30. rewrite: (path) => path.replace(/^\/miniapp-api/, '')
  31. },
  32. // 管理后台后端代理
  33. [env.VITE_APP_BASE_API]: {
  34. target: 'http://localhost:8080',
  35. // target: 'https://www.whzhangsheng.cn/admin-api/',
  36. changeOrigin: true,
  37. ws: true,
  38. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  39. }
  40. }
  41. },
  42. css: {
  43. preprocessorOptions: {
  44. scss: {
  45. // additionalData: '@use "@/assets/styles/variables.module.scss as *";'
  46. // javascriptEnabled: true
  47. api: 'modern-compiler'
  48. }
  49. },
  50. postcss: {
  51. plugins: [
  52. // 浏览器兼容性
  53. autoprefixer(),
  54. {
  55. postcssPlugin: 'internal:charset-removal',
  56. AtRule: {
  57. charset: (atRule) => {
  58. atRule.remove();
  59. }
  60. }
  61. }
  62. ]
  63. }
  64. },
  65. // 预编译
  66. optimizeDeps: {
  67. include: [
  68. 'vue',
  69. 'vue-router',
  70. 'pinia',
  71. 'axios',
  72. '@vueuse/core',
  73. 'echarts',
  74. 'vue-i18n',
  75. '@vueup/vue-quill',
  76. 'image-conversion',
  77. 'element-plus/es/components/**/css'
  78. ]
  79. }
  80. };
  81. });