邃芒慧影管理端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

118 lines
3.7 KiB

  1. import vue from "@vitejs/plugin-vue";
  2. import { UserConfig, ConfigEnv, loadEnv, defineConfig } from "vite";
  3. import AutoImport from "unplugin-auto-import/vite";
  4. import Components from "unplugin-vue-components/vite";
  5. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  6. import Icons from "unplugin-icons/vite";
  7. import IconsResolver from "unplugin-icons/resolver";
  8. import postCssPxToRem from 'postcss-pxtorem'
  9. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  10. import UnoCSS from "unocss/vite";
  11. import path from "path";
  12. const pathSrc = path.resolve(__dirname, "src");
  13. export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  14. const env = loadEnv(mode, process.cwd());
  15. return {
  16. resolve: {
  17. alias: {
  18. "@": pathSrc,
  19. },
  20. },
  21. css: {
  22. // CSS 预处理器
  23. preprocessorOptions: {
  24. //define global scss variable
  25. scss: {
  26. javascriptEnabled: true,
  27. additionalData: `
  28. @use "@/styles/variables.scss" as *;
  29. `,
  30. },
  31. },
  32. // postcss: {
  33. // plugins: [
  34. // postCssPxToRem({
  35. // rootValue: 192, // 1rem 的大小
  36. // propList: ['*'], // 需要转换的属性,*(全部转换)
  37. // unitPrecision: 6 // 转换精度,保留的小数位数
  38. // })
  39. // ]
  40. // }
  41. },
  42. server: {
  43. host: "0.0.0.0",
  44. port: Number(env.VITE_APP_PORT),
  45. open: true, // 运行是否自动打开浏览器
  46. // "/api": {
  47. // target: env.VITE_APP_BASE_API, // 线上接口地址
  48. // changeOrigin: true,
  49. // rewrite: (path) => path.replace(/^\/api/, ""),
  50. // },
  51. proxy: {
  52. // 反向代理解决跨域
  53. "/A": {
  54. target: env.VITE_APP_BASE_API, // 线上接口地址
  55. changeOrigin: true,
  56. rewrite: (path) => path.replace(/^\/A/, ""),
  57. },
  58. },
  59. },
  60. plugins: [
  61. vue(),
  62. UnoCSS({
  63. /* options */
  64. }),
  65. AutoImport({
  66. // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
  67. imports: ["vue", "@vueuse/core"],
  68. // eslintrc: {
  69. // enabled: false, // Default `false`
  70. // filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json`
  71. // globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
  72. // },
  73. resolvers: [
  74. // 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
  75. ElementPlusResolver(),
  76. // 自动导入图标组件
  77. IconsResolver({}),
  78. ],
  79. vueTemplate: true, // 是否在 vue 模板中自动导入
  80. dts: path.resolve(pathSrc, "types", "auto-imports.d.ts"), // 自动导入组件类型声明文件位置,默认根目录; false 关闭自动生成
  81. }),
  82. Components({
  83. resolvers: [
  84. // 自动注册图标组件
  85. IconsResolver({
  86. enabledCollections: ["ep"], //@iconify-json/ep 是 Element Plus 的图标库
  87. }),
  88. // 自动导入 Element Plus 组件
  89. ElementPlusResolver(),
  90. ],
  91. dts: path.resolve(pathSrc, "types", "components.d.ts"), // 自动导入组件类型声明文件位置,默认根目录; false 关闭自动生成
  92. }),
  93. Icons({
  94. // 自动安装图标库
  95. autoInstall: true,
  96. }),
  97. createSvgIconsPlugin({
  98. // 指定需要缓存的图标文件夹
  99. iconDirs: [path.resolve(pathSrc, "assets/icons")],
  100. // 指定symbolId格式
  101. symbolId: "icon-[dir]-[name]",
  102. }),
  103. ],
  104. // define: {
  105. // global: {},
  106. // },
  107. };
  108. });