vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. build: {
  35. rollupOptions: {
  36. input: {
  37. index: path.resolve(__dirname, 'index.html'),
  38. login: path.resolve(__dirname, 'login.html')
  39. },
  40. output: { // 静态资源分类打包
  41. chunkFileNames: 'js/[hash].js',
  42. entryFileNames: 'js/[hash].js',
  43. assetFileNames: 'assets/[ext]/[hash].[ext]',
  44. // 拆分node_modules包
  45. manualChunks: (id: any) => {
  46. if (id.includes("node_modules")) {
  47. return id
  48. .toString()
  49. .split("node_modules/")[1]
  50. .split("/")[0]
  51. .toString();
  52. }
  53. }
  54. }
  55. }
  56. },
  57. define: {
  58. __VUE_OPTIONS_API__: false
  59. }
  60. })