vite.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { defineConfig, loadEnv } 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(({ command, mode }) => {
  9. const config = loadEnv(mode, './')
  10. return {
  11. resolve: {
  12. alias: [{
  13. find: "@",
  14. replacement: pathResolve("src"),
  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. modifyVars: {
  33. "arcoblue-6": "#0f2d5c",
  34. },
  35. javascriptEnabled: true,
  36. additionalData: '@import "@/assets/css/theme.less";@import "@/assets/css/global.less";',
  37. },
  38. },
  39. },
  40. build: {
  41. minify: true, // 生产环境不生成sourcemap
  42. target: "es2015",
  43. // 警报门槛,限制大文件大小
  44. chunkSizeWarningLimit: 5000,
  45. rollupOptions: {
  46. external: [], // 外部化处理那些你不想打包进库的依赖
  47. // 静态资源分类打包
  48. output: {
  49. chunkFileNames: "static/js/[name]-[hash].js",
  50. entryFileNames: "static/js/[name]-[hash].js",
  51. assetFileNames: "static/[ext]/[name]-[hash].[ext]",
  52. },
  53. },
  54. },
  55. server: {
  56. port: 8088,
  57. host: "0.0.0.0",
  58. open: true,
  59. cors: true,
  60. hmr: true,
  61. proxy: {
  62. "/api": {
  63. // target:"https://sim.nanodreamtech.com",
  64. // target: config.VITE_API_URL,
  65. target: "https://flexi.flexistream.link",
  66. changeOrigin: true,
  67. ws: true,
  68. secure: true,
  69. },
  70. },
  71. },
  72. }
  73. });