vite.config.ts 1.8 KB

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