vite.config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite';
  2. import createPlugins from './vite/plugins';
  3. import path from 'path';
  4. export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
  5. const env = loadEnv(mode, process.cwd());
  6. return {
  7. // 部署生产环境和开发环境下的URL。
  8. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  9. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  10. base: env.VITE_APP_CONTEXT_PATH,
  11. resolve: {
  12. alias: {
  13. '~': path.resolve(__dirname, './'),
  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:8080',
  27. changeOrigin: true,
  28. ws: true,
  29. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  30. }
  31. }
  32. },
  33. css: {
  34. preprocessorOptions: {
  35. scss: {
  36. javascriptEnabled: true
  37. }
  38. },
  39. postcss: {
  40. plugins: [
  41. {
  42. postcssPlugin: 'internal:charset-removal',
  43. AtRule: {
  44. charset: (atRule) => {
  45. if (atRule.name === 'charset') {
  46. atRule.remove();
  47. }
  48. }
  49. }
  50. }
  51. ]
  52. }
  53. },
  54. // 预编译
  55. optimizeDeps: {
  56. include: [
  57. 'vue',
  58. 'vue-router',
  59. 'pinia',
  60. 'axios',
  61. '@vueuse/core',
  62. 'echarts',
  63. 'vue-i18n',
  64. '@vueup/vue-quill',
  65. 'image-conversion',
  66. 'element-plus/es/components/**/css'
  67. ]
  68. }
  69. };
  70. });