vite.config.js 2.1 KB

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