vite.config.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { defineConfig, loadEnv, ConfigEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "path";
  4. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  5. import AutoImport from "unplugin-auto-import/vite";
  6. import Components from "unplugin-vue-components/vite";
  7. import IconsResolver from "unplugin-icons/resolver";
  8. import Icons from "unplugin-icons/vite";
  9. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  10. import { VueUseComponentsResolver } from "unplugin-vue-components/resolvers";
  11. import postcsspxtoviewport from "postcss-px-to-viewport";
  12. import legacyPlugin from "@vitejs/plugin-legacy";
  13. // https://vitejs.dev/config/
  14. export default ({ mode }: ConfigEnv) => {
  15. const env = loadEnv(mode, process.cwd());
  16. return defineConfig({
  17. plugins: [
  18. vue(),
  19. createSvgIconsPlugin({
  20. iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
  21. symbolId: "icon-[dir]-[name]",
  22. }),
  23. AutoImport({
  24. imports: ["vue", "vue-router", "pinia", "@vueuse/core", { axios: [["default", "axios"]] }],
  25. resolvers: [ElementPlusResolver(), IconsResolver({})],
  26. vueTemplate: true,
  27. dts: path.resolve(__dirname, "types", "auto-imports.d.ts"),
  28. }),
  29. Components({
  30. resolvers: [ElementPlusResolver(), IconsResolver({ prefix: "icon", enabledCollections: ["ep"] }), VueUseComponentsResolver()],
  31. dts: path.resolve(__dirname, "types", "components.d.ts"),
  32. }),
  33. // 图标库 'https://fontawesome.com.cn/v5' 'https://icones.netlify.app/' 'https://icon-sets.iconify.design/'
  34. Icons({ autoInstall: true }),
  35. legacyPlugin({
  36. targets: ["chrome 52"], // 需要兼容的目标列表,可以设置多个
  37. additionalLegacyPolyfills: ["regenerator-runtime/runtime"], // 面向IE11时需要此插件
  38. }),
  39. ],
  40. resolve: {
  41. alias: {
  42. "@": path.resolve(__dirname, "./src"),
  43. },
  44. },
  45. css: {
  46. preprocessorOptions: {
  47. scss: {
  48. additionalData: `@import "@/assets/styles/variables.scss";`,
  49. javascriptEnabled: true,
  50. },
  51. },
  52. postcss: {
  53. plugins: [
  54. postcsspxtoviewport({
  55. unitToConvert: "px", // 要转化的单位
  56. viewportWidth: 1920, // 要转化的单位
  57. unitPrecision: 6, // 转换后的精度,即小数点位数
  58. propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  59. viewportUnit: "vw", // 指定需要转换成的视窗单位,默认vw
  60. fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位,默认vw
  61. selectorBlackList: [], // 指定不转换为视窗单位的类名,
  62. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  63. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  64. replace: true, // 是否转换后直接更换属性值
  65. landscape: false, // 是否处理横屏情况
  66. }),
  67. ],
  68. },
  69. },
  70. // server: {
  71. // host: "0.0.0.0",
  72. // port: 80,
  73. // proxy: {
  74. // "/api": {
  75. // target: "http://localhost:8080",
  76. // ws: true,
  77. // changeOrigin: true,
  78. // rewrite: (path) => path.replace(/^\/api/, ""),
  79. // },
  80. // },
  81. // },
  82. });
  83. };