vite.config.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { resolve } from 'path'
  2. import vue from '@vitejs/plugin-vue'
  3. import type { UserConfig } from 'vite'
  4. import { loadEnv } from './build/utils'
  5. import { createProxy } from './build/proxy'
  6. const pathResolve = (dir: string): any => {
  7. return resolve(__dirname, '.', dir)
  8. }
  9. const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_OPEN } = loadEnv()
  10. const alias: Record<string, string> = {
  11. '/@': pathResolve('src'),
  12. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js' //解决警告You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
  13. }
  14. const root: string = process.cwd()
  15. const viteConfig: UserConfig = {
  16. /**
  17. * 基本公共路径
  18. * @default '/'
  19. */
  20. base: process.env.NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH,
  21. root,
  22. resolve: {
  23. alias
  24. },
  25. // 服务端渲染
  26. server: {
  27. // 是否开启 https
  28. https: false,
  29. /**
  30. * 端口号
  31. * @default 3000
  32. */
  33. port: VITE_PORT,
  34. // 本地跨域代理
  35. proxy: createProxy(VITE_PROXY)
  36. },
  37. plugins: [
  38. vue(),
  39. ],
  40. build: {
  41. brotliSize: false,
  42. // 消除打包大小超过500kb警告
  43. chunkSizeWarningLimit: 800
  44. }
  45. }
  46. export default viteConfig