vite.config.js 2.4 KB

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