vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { resolve } from 'path'
  2. import { UserConfigExport, ConfigEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import { loadEnv } from './build/utils'
  5. import { createProxy } from './build/proxy'
  6. import { viteMockServe } from 'vite-plugin-mock'
  7. const pathResolve = (dir: string): any => {
  8. return resolve(__dirname, '.', dir)
  9. }
  10. const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_OPEN } = loadEnv()
  11. const alias: Record<string, string> = {
  12. '/@': pathResolve('src'),
  13. '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.
  14. }
  15. const root: string = process.cwd()
  16. export default ({ command }: ConfigEnv): UserConfigExport => {
  17. let prodMock = true
  18. return {
  19. /**
  20. * 基本公共路径
  21. * @default '/'
  22. */
  23. base: process.env.NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH,
  24. root,
  25. resolve: {
  26. alias
  27. },
  28. // 服务端渲染
  29. server: {
  30. // 是否开启 https
  31. https: false,
  32. /**
  33. * 端口号
  34. * @default 3000
  35. */
  36. port: VITE_PORT,
  37. // 本地跨域代理
  38. proxy: createProxy(VITE_PROXY)
  39. },
  40. plugins: [
  41. vue(),
  42. viteMockServe({
  43. mockPath: 'mock',
  44. localEnabled: command === 'serve',
  45. prodEnabled: command !== 'serve' && prodMock,
  46. injectCode: `
  47. import { setupProdMockServer } from './mockProdServer';
  48. setupProdMockServer();
  49. `,
  50. logger: true,
  51. }),
  52. ],
  53. build: {
  54. brotliSize: false,
  55. // 消除打包大小超过500kb警告
  56. chunkSizeWarningLimit: 2000
  57. }
  58. }
  59. }