vite.config.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "path";
  4. import AutoImport from "unplugin-auto-import/vite";
  5. import Components from "unplugin-vue-components/vite";
  6. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  7. import postcsspxtoviewport from "postcss-px-to-viewport";
  8. import {fileURLToPath, URL} from "node:url";
  9. // https://vite.dev/config/
  10. export default defineConfig({
  11. base: process.env.NODE_ENV === "development" ? "/" : "/eoc_webgis_test/",
  12. server: {
  13. host: 'localhost',
  14. port: 5173,
  15. open: true,
  16. },
  17. resolve: {
  18. // https://cn.vitejs.dev/config/#resolve-alias
  19. alias: {
  20. // 设置路径
  21. "~": path.resolve(__dirname, "./"),
  22. // 设置别名
  23. "@": path.resolve(__dirname, "./src"),
  24. },
  25. // https://cn.vitejs.dev/config/#resolve-extensions
  26. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  27. },
  28. optimizeDeps: {
  29. // 开发时 解决这些commonjs包转成esm包
  30. include: [
  31. "@jiaminghi/c-render",
  32. "@jiaminghi/c-render/lib/plugin/util",
  33. "@jiaminghi/charts/lib/util/index",
  34. "@jiaminghi/charts/lib/util",
  35. "@jiaminghi/charts/lib/extend/index",
  36. "@jiaminghi/charts",
  37. "@jiaminghi/color",
  38. "highcharts",
  39. "highcharts/highcharts-3d",
  40. ],
  41. },
  42. plugins: [
  43. vue(),
  44. AutoImport({
  45. resolvers: [ElementPlusResolver()],
  46. }),
  47. Components({
  48. resolvers: [ElementPlusResolver()],
  49. }),
  50. ],
  51. css: {
  52. postcss: {
  53. plugins: [
  54. postcsspxtoviewport({
  55. unitToConvert: "px", // 要转化的单位
  56. // viewportHeight: 1080, // 可选,视口高度,通常不需要设置
  57. viewportWidth: 3840, // UI设计稿的宽度
  58. unitPrecision: 4, // 转换后的精度,即小数点位数
  59. propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  60. // viewportUnit: 'vh', // 指定需要转换成的视窗单位,默认vw
  61. // fontViewportUnit: 'vh', // 指定字体需要转换成的视窗单位,默认vw
  62. viewportUnit: "vw", // 指定需要转换成的视窗单位,默认vw
  63. fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位,默认vw
  64. selectorBlackList: [], // 指定不转换为视窗单位的类名,
  65. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  66. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  67. replace: true, // 是否转换后直接更换属性值
  68. exclude: [/node_modules\/(?!element-plus)/], // 设置忽略文件,用正则做目录名匹配
  69. landscape: false, // 是否处理横屏情况
  70. }),
  71. ],
  72. },
  73. },
  74. build: {
  75. sourcemap: false,
  76. },
  77. });