vite.config.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {defineConfig, loadEnv} from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // const baseUrl = 'http://192.168.110.235:8040' // 后端接口
  5. const baseUrl = 'http://localhost:8040' // 后端接口
  6. // const baseUrl = 'http://47.107.107.47:8040' // 后端接口
  7. // https://vitejs.dev/config/
  8. export default defineConfig(({ mode, command }) => {
  9. const env = loadEnv(mode, process.cwd())
  10. const { VITE_APP_ENV } = env
  11. return {
  12. // 部署生产环境和开发环境下的URL。
  13. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  14. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  15. base: VITE_APP_ENV === 'production' ? '/' : '/',
  16. plugins: createVitePlugins(env, command === 'build'),
  17. resolve: {
  18. // https://cn.vitejs.dev/config/#resolve-alias
  19. alias: {
  20. // 设置路径
  21. '~': path.resolve(__dirname, './'),
  22. // 设置别名
  23. '@': path.resolve(__dirname, './src'),
  24. 'quill-image-resize-module': 'quill-image-resize-module/dist/quill-image-resize-module.esm.js'
  25. },
  26. // https://cn.vitejs.dev/config/#resolve-extensions
  27. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  28. },
  29. // 打包配置
  30. build: {
  31. // https://vite.dev/config/build-options.html
  32. sourcemap: command === 'build' ? false : 'inline',
  33. outDir: 'dist',
  34. assetsDir: 'assets',
  35. chunkSizeWarningLimit: 2000,
  36. rollupOptions: {
  37. output: {
  38. chunkFileNames: 'static/js/[name]-[hash].js',
  39. entryFileNames: 'static/js/[name]-[hash].js',
  40. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  41. }
  42. }
  43. },
  44. // vite 相关配置
  45. server: {
  46. port: 81,
  47. host: true,
  48. open: true,
  49. proxy: {
  50. // https://cn.vitejs.dev/config/#server-proxy
  51. '/dev-api': {
  52. target: baseUrl,
  53. changeOrigin: true,
  54. rewrite: (p) => p.replace(/^\/dev-api/, '')
  55. },
  56. // springdoc proxy
  57. '^/v3/api-docs/(.*)': {
  58. target: baseUrl,
  59. changeOrigin: true,
  60. }
  61. }
  62. },
  63. css: {
  64. postcss: {
  65. plugins: [
  66. {
  67. postcssPlugin: 'internal:charset-removal',
  68. AtRule: {
  69. charset: (atRule) => {
  70. if (atRule.name === 'charset') {
  71. atRule.remove()
  72. }
  73. }
  74. }
  75. }
  76. ]
  77. }
  78. }
  79. }
  80. })