vite.config.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import { visualizer } from 'rollup-plugin-visualizer'
  6. export default ({ mode }) => {
  7. const env = loadEnv(mode, process.cwd())
  8. const proxyPrefix = env.VITE_APP_PROXY_PREFIX
  9. return defineConfig({
  10. base: env.VITE_APP_BASE,
  11. plugins: [
  12. vue(),
  13. vueJsx(),
  14. visualizer({
  15. emitFile: false,
  16. file: 'stats.html', //分析图生成的文件名
  17. open: true //如果存在本地服务端口,将在打包后自动展示
  18. })
  19. ],
  20. resolve: {
  21. alias: {
  22. '@': resolve(__dirname, 'src'),
  23. '@cps': resolve(__dirname, 'src/components'),
  24. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  25. }
  26. },
  27. build: {
  28. chunkSizeWarningLimit: 1500
  29. // rollupOptions: {
  30. // output: {
  31. // manualChunks(id) {
  32. // if (id.includes('node_modules')) {
  33. // return id.toString().split("node_modules/")[1].split("/")[0].toString();
  34. // }
  35. // }
  36. // }
  37. // }
  38. },
  39. server: {
  40. host: '0.0.0.0',
  41. port: env.VITE_APP_PORT || process.env.port,
  42. proxy: {
  43. [proxyPrefix]: {
  44. target: env.VITE_APP_BASE_URL,
  45. changeOrigin: true,
  46. ws: true,
  47. toProxy: true,
  48. rewrite: (path) => path.replace(new RegExp(`^${proxyPrefix}`), '')
  49. }
  50. }
  51. }
  52. })
  53. }