vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import vue from '@vitejs/plugin-vue';
  2. import { resolve } from 'path';
  3. import { defineConfig, loadEnv, ConfigEnv } from 'vite';
  4. import vueSetupExtend from 'vite-plugin-vue-setup-extend'; // setup语法糖设置name
  5. const pathResolve = (dir: string): any => {
  6. return resolve(__dirname, '.', dir);
  7. };
  8. const alias: Record<string, string> = {
  9. '/@': pathResolve('./src/'),
  10. };
  11. const viteConfig = defineConfig((mode: ConfigEnv) => {
  12. const env = loadEnv(mode.mode, process.cwd());
  13. return {
  14. plugins: [
  15. vue(),
  16. vueSetupExtend()
  17. ],
  18. root: process.cwd(),
  19. resolve: { alias },
  20. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  21. hmr: true,
  22. server: {
  23. host: '0.0.0.0',
  24. port: env.VITE_PORT as unknown as number,
  25. open: false, // 是否打开浏览器
  26. proxy: {
  27. '/api': {
  28. target: 'http://hotline.fw.com',
  29. ws: true,
  30. changeOrigin: true,
  31. rewrite: (path) => path.replace(/^\/api/, ''),
  32. },
  33. }
  34. },
  35. build: {
  36. outDir: 'dist',
  37. sourcemap: false,
  38. chunkSizeWarningLimit: 1500,
  39. rollupOptions: {
  40. output: {
  41. entryFileNames: `assets/[name].[hash].js`,
  42. chunkFileNames: `assets/[name].[hash].js`,
  43. assetFileNames: `assets/[name].[hash].[ext]`,
  44. compact: true,
  45. manualChunks: {
  46. vue: ['vue', 'vue-router', 'pinia'],
  47. echarts: ['echarts'],
  48. },
  49. },
  50. },
  51. minify: 'terser',
  52. terserOptions: {
  53. //生产环境时移除console
  54. compress: {
  55. drop_console: false,
  56. drop_debugger: true
  57. }
  58. }
  59. },
  60. css: { preprocessorOptions: { css: { charset: false } } },
  61. };
  62. });
  63. export default viteConfig;