vite.config.js 2.2 KB

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