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