vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. [env.VITE_APP_BASE_API]: {
  26. target: 'http://localhost:8081/api',
  27. // target: 'http://jtjai.xt.wenhq.top:8083/api',
  28. changeOrigin: true,
  29. ws: true,
  30. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  31. },
  32. '/loadFile': {
  33. target: 'http://localhost:8081',
  34. // target: 'http://jtjai.xt.wenhq.top:8083/',
  35. changeOrigin: true,
  36. ws: true,
  37. rewrite: (path) => path.replace(new RegExp('^' + '/loadFile'), '')
  38. }
  39. }
  40. },
  41. css: {
  42. preprocessorOptions: {
  43. scss: {
  44. // additionalData: '@use "@/assets/styles/variables.module.scss as *";'
  45. // javascriptEnabled: true
  46. api: 'modern-compiler'
  47. }
  48. },
  49. postcss: {
  50. plugins: [
  51. // 浏览器兼容性
  52. autoprefixer(),
  53. {
  54. postcssPlugin: 'internal:charset-removal',
  55. AtRule: {
  56. charset: (atRule) => {
  57. atRule.remove();
  58. }
  59. }
  60. }
  61. ]
  62. }
  63. },
  64. // 预编译
  65. optimizeDeps: {
  66. include: [
  67. 'vue',
  68. 'vue-router',
  69. 'pinia',
  70. 'axios',
  71. '@vueuse/core',
  72. 'echarts',
  73. 'vue-i18n',
  74. '@vueup/vue-quill',
  75. 'image-conversion',
  76. 'element-plus/es/components/**/css'
  77. ]
  78. }
  79. };
  80. });