vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, './'),
  15. '@': path.resolve(__dirname, './src')
  16. },
  17. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  18. },
  19. // https://cn.vitejs.dev/config/#resolve-extensions
  20. plugins: createPlugins(env, command === 'build'),
  21. server: {
  22. host: '0.0.0.0',
  23. port: Number(env.VITE_APP_PORT),
  24. open: true,
  25. proxy: {
  26. [env.VITE_APP_BASE_API]: {
  27. target: 'http://localhost:8080',
  28. changeOrigin: true,
  29. ws: true,
  30. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  31. }
  32. }
  33. },
  34. css: {
  35. preprocessorOptions: {
  36. scss: {
  37. // additionalData: '@use "@/assets/styles/variables.module.scss as *";'
  38. // javascriptEnabled: true
  39. api: 'modern-compiler'
  40. }
  41. },
  42. postcss: {
  43. plugins: [
  44. // 浏览器兼容性
  45. autoprefixer({
  46. overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8']
  47. }),
  48. {
  49. postcssPlugin: 'internal:charset-removal',
  50. AtRule: {
  51. charset: (atRule) => {
  52. if (atRule.name === 'charset') {
  53. atRule.remove();
  54. }
  55. }
  56. }
  57. }
  58. ]
  59. }
  60. },
  61. // 预编译
  62. optimizeDeps: {
  63. include: [
  64. 'vue',
  65. 'vue-router',
  66. 'pinia',
  67. 'axios',
  68. '@vueuse/core',
  69. 'echarts',
  70. 'vue-i18n',
  71. '@vueup/vue-quill',
  72. 'image-conversion',
  73. 'element-plus/es/components/**/css'
  74. ]
  75. }
  76. };
  77. });