vite.config.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import legacy from '@vitejs/plugin-legacy'
  4. import path from 'path'
  5. // https://vitejs.dev/config/
  6. export default defineConfig({
  7. plugins: [
  8. vue(),
  9. legacy({
  10. polyfills: ['es.promise.finally', 'es/map', 'es/set'],
  11. modernPolyfills: ['es.promise.finally']
  12. })
  13. ],
  14. server: {
  15. port: 3000,
  16. cors: true,
  17. host: '0.0.0.0',
  18. proxy: {
  19. '/v1': {
  20. // target: 'http://8.136.199.33:8608',
  21. target: 'https://charttest.hzinsights.com',
  22. changeOrigin: true,
  23. rewrite: (path) => path.replace(/^\/v1/, '/v1')
  24. }
  25. },
  26. },
  27. build: {
  28. outDir: 'horz_chart',
  29. chunkSizeWarningLimit: 800,//单文件过800kb警告
  30. rollupOptions: {
  31. output: {
  32. manualChunks(id) {
  33. if (id.includes('node_modules')) {
  34. return id.toString()
  35. .split('node_modules/')[1]
  36. .split('/')[0]
  37. .toString();
  38. }
  39. },
  40. chunkFileNames: (info) => {
  41. const facadeModuleId = info.facadeModuleId ?
  42. info.facadeModuleId.split('/') : [];
  43. const fileName = facadeModuleId[facadeModuleId.length -2] || '[name]'
  44. return `js/${fileName}/[name].[hash].js`;
  45. }
  46. }
  47. }
  48. },
  49. resolve: {
  50. alias: {
  51. '@': path.resolve(__dirname, './src')
  52. },
  53. },
  54. css: {
  55. postcss: {
  56. plugins: [
  57. {
  58. postcssPlugin: 'internal:charset-removal',
  59. AtRule: {
  60. charset: (atRule) => {
  61. if (atRule.name === 'charset') {
  62. atRule.remove()
  63. }
  64. }
  65. }
  66. }
  67. ]
  68. }
  69. }
  70. })