vite.config.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import eslint from 'vite-plugin-eslint'
  4. import viteCompression from 'vite-plugin-compression'
  5. import path from 'path'
  6. // https://vitejs.dev/config/
  7. export default defineConfig({
  8. base: './',
  9. resolve: {
  10. alias: {
  11. /*
  12. 路径别名
  13. 若为文件系统路径必须是绝对路径的形式,否则将以别名原样呈现,不会解析为文件系统路径路径
  14. */
  15. '@': path.resolve(__dirname, './src')
  16. }
  17. },
  18. plugins: [vue(), viteCompression(), eslint({ fix: true, include: ['**/*.ts', '**/*.vue'] })],
  19. server: {
  20. host: '0.0.0.0',
  21. port: 5888,
  22. open: true,
  23. strictPort: false,
  24. https: false
  25. // 反向代理
  26. // proxy: {
  27. // '/': {
  28. // target: 'http://172.16.1.215:5000',
  29. // changeOrigin: true,
  30. // rewrite: (path) => path.replace(/^\//, '')
  31. // },
  32. // }
  33. },
  34. esbuild: {
  35. drop: ['console', 'debugger'] //build 移除打印
  36. },
  37. build: {
  38. rollupOptions: {
  39. input: {
  40. index: path.resolve(__dirname, 'index.html'),
  41. login: path.resolve(__dirname, 'login.html')
  42. },
  43. output: { // 静态资源分类打包
  44. chunkFileNames: 'js/[hash].js',
  45. entryFileNames: 'js/[hash].js',
  46. assetFileNames: 'assets/[ext]/[hash].[ext]',
  47. // 拆分node_modules包
  48. manualChunks: (id: any) => {
  49. if (id.includes("node_modules")) {
  50. return id.toString().split("node_modules/")[1].split("/")[0].toString()
  51. }
  52. }
  53. }
  54. }
  55. },
  56. define: {
  57. __VUE_OPTIONS_API__: false
  58. }
  59. })