vite.config.js 2.5 KB

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