vite.config.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  4. import { resolve } from 'path'
  5. function pathResolve(dir) {
  6. return resolve(process.cwd(), '.', dir)
  7. }
  8. export default defineConfig({
  9. resolve: {
  10. alias: [
  11. {
  12. find: '@',
  13. replacement: pathResolve('src')
  14. }
  15. ],
  16. dedupe: ['vue']
  17. },
  18. plugins: [
  19. vue(),
  20. createSvgIconsPlugin({
  21. // 指定需要缓存的图标文件夹
  22. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  23. // 指定symbolId格式
  24. symbolId: 'icon-[dir]-[name]',
  25. })
  26. ],
  27. css: {
  28. // css预处理器
  29. preprocessorOptions: {
  30. less: {
  31. charset: false,
  32. additionalData:
  33. '@import "@/assets/css/theme.less";@import "@/assets/css/global.less";',
  34. },
  35. },
  36. },
  37. build: {
  38. minify: true, // 生产环境不生成sourcemap
  39. target: 'es2015',
  40. // 警报门槛,限制大文件大小
  41. chunkSizeWarningLimit: 5000,
  42. rollupOptions: {
  43. external: [], // 外部化处理那些你不想打包进库的依赖
  44. // 静态资源分类打包
  45. output: {
  46. chunkFileNames: 'static/js/[name]-[hash].js',
  47. entryFileNames: 'static/js/[name]-[hash].js',
  48. assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
  49. },
  50. },
  51. },
  52. server: {
  53. port: 8088,
  54. host: '0.0.0.0',
  55. open: true,
  56. cors: true,
  57. hmr: true,
  58. proxy: {
  59. '/api': {
  60. target: "http://sim.nanodreamtech.com",
  61. changeOrigin: true,
  62. ws: true,
  63. secure: true,
  64. },
  65. }
  66. }
  67. })