vite.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. import tailwindcss from '@tailwindcss/vite'
  5. // const baseUrl = 'http://localhost:8080' // 后端接口
  6. const baseUrl = 'https://dz.shineking.top/prod-api' // 后端接口
  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' ? '/admin/' : '/admin/',
  16. plugins: [createVitePlugins(env, command === 'build'), tailwindcss()],
  17. resolve: {
  18. // https://cn.vitejs.dev/config/#resolve-alias
  19. alias: {
  20. // 设置路径
  21. '~': path.resolve(__dirname, './'),
  22. // 设置别名
  23. '@': path.resolve(__dirname, './src')
  24. },
  25. // https://cn.vitejs.dev/config/#resolve-extensions
  26. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  27. },
  28. // 打包配置
  29. build: {
  30. // https://vite.dev/config/build-options.html
  31. sourcemap: command === 'build' ? false : 'inline',
  32. outDir: 'admin',
  33. assetsDir: 'assets',
  34. chunkSizeWarningLimit: 2000,
  35. rollupOptions: {
  36. output: {
  37. chunkFileNames: 'static/js/[name]-[hash].js',
  38. entryFileNames: 'static/js/[name]-[hash].js',
  39. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  40. }
  41. }
  42. },
  43. // vite 相关配置
  44. server: {
  45. port: 8108,
  46. host: true,
  47. open: true,
  48. proxy: {
  49. // https://cn.vitejs.dev/config/#server-proxy
  50. '/dev-api': {
  51. target: baseUrl,
  52. changeOrigin: true,
  53. rewrite: (p) => p.replace(/^\/dev-api/, '')
  54. },
  55. // springdoc proxy
  56. '^/v3/api-docs/(.*)': {
  57. target: baseUrl,
  58. changeOrigin: true,
  59. }
  60. }
  61. },
  62. css: {
  63. postcss: {
  64. plugins: [
  65. {
  66. postcssPlugin: 'internal:charset-removal',
  67. AtRule: {
  68. charset: (atRule) => {
  69. if (atRule.name === 'charset') {
  70. atRule.remove()
  71. }
  72. }
  73. }
  74. }
  75. ]
  76. }
  77. }
  78. }
  79. })